Andrey Smirnov dfcbaae7d0
chore: initial commit
Omni is source-available under BUSL.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
Co-Authored-By: Artem Chernyshev <artem.chernyshev@talos-systems.com>
Co-Authored-By: Utku Ozdemir <utku.ozdemir@siderolabs.com>
Co-Authored-By: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
Co-Authored-By: Philipp Sauter <philipp.sauter@siderolabs.com>
Co-Authored-By: Noel Georgi <git@frezbo.dev>
Co-Authored-By: evgeniybryzh <evgeniybryzh@gmail.com>
Co-Authored-By: Tim Jones <tim.jones@siderolabs.com>
Co-Authored-By: Andrew Rynhard <andrew@rynhard.io>
Co-Authored-By: Spencer Smith <spencer.smith@talos-systems.com>
Co-Authored-By: Christian Rolland <christian.rolland@siderolabs.com>
Co-Authored-By: Gerard de Leeuw <gdeleeuw@leeuwit.nl>
Co-Authored-By: Steve Francis <67986293+steverfrancis@users.noreply.github.com>
Co-Authored-By: Volodymyr Mazurets <volodymyrmazureets@gmail.com>
2024-02-29 17:19:57 +04:00

56 lines
1.3 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package operations
import (
"context"
"fmt"
"io"
"github.com/cosi-project/runtime/pkg/state"
"github.com/siderolabs/omni/client/pkg/template"
"github.com/siderolabs/omni/client/pkg/template/operations/internal/utils"
)
// DiffTemplate outputs the diff between template resources and existing resources.
func DiffTemplate(ctx context.Context, templateReader io.Reader, output io.Writer, st state.State) error {
tmpl, err := template.Load(templateReader)
if err != nil {
return fmt.Errorf("error loading template: %w", err)
}
if err = tmpl.Validate(); err != nil {
return err
}
syncResult, err := tmpl.Sync(ctx, st)
if err != nil {
return fmt.Errorf("error syncing template: %w", err)
}
for _, p := range syncResult.Update {
if err = utils.RenderDiff(output, p.Old, p.New); err != nil {
return err
}
}
for _, r := range syncResult.Create {
if err = utils.RenderDiff(output, nil, r); err != nil {
return err
}
}
for _, phase := range syncResult.Destroy {
for _, r := range phase {
if err = utils.RenderDiff(output, r, nil); err != nil {
return err
}
}
}
return nil
}