package flux import ( "context" _ "embed" //nolint let a human embed "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/controller-runtime/pkg/client" "edge-infra.dev/third_party/k8s/fluxcd" ) // LoadManifests decodes the embedded Flux installation manifests into an array // of K8s resources func LoadManifests() ([]*unstructured.Unstructured, error) { return fluxcd.LoadManifests() } // Install applies loaded manifests to K8s. This function does not need to care about // resource ordering (e.g., namespace) because all resources are cluster-scoped or // installed to existing namespaces func Install(ctx context.Context, c client.Client, manifests []*unstructured.Unstructured) error { // apply namespace first for _, manifest := range manifests { if manifest.GetKind() == "Namespace" { if err := c.Create(ctx, manifest); err != nil && !errors.IsAlreadyExists(err) { return err } } } // apply everything else for _, manifest := range manifests { if manifest.GetKind() != "Namespace" { if err := c.Create(ctx, manifest); err != nil && !errors.IsAlreadyExists(err) { return err } } } return nil }