...

Source file src/edge-infra.dev/pkg/edge/flux/install.go

Documentation: edge-infra.dev/pkg/edge/flux

     1  package flux
     2  
     3  import (
     4  	"context"
     5  	_ "embed" //nolint let a human embed
     6  
     7  	"k8s.io/apimachinery/pkg/api/errors"
     8  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     9  	"sigs.k8s.io/controller-runtime/pkg/client"
    10  
    11  	"edge-infra.dev/third_party/k8s/fluxcd"
    12  )
    13  
    14  // LoadManifests decodes the embedded Flux installation manifests into an array
    15  // of K8s resources
    16  func LoadManifests() ([]*unstructured.Unstructured, error) {
    17  	return fluxcd.LoadManifests()
    18  }
    19  
    20  // Install applies loaded manifests to K8s.  This function does not need to care about
    21  // resource ordering (e.g., namespace) because all resources are cluster-scoped or
    22  // installed to existing namespaces
    23  func Install(ctx context.Context, c client.Client, manifests []*unstructured.Unstructured) error {
    24  	// apply namespace first
    25  	for _, manifest := range manifests {
    26  		if manifest.GetKind() == "Namespace" {
    27  			if err := c.Create(ctx, manifest); err != nil && !errors.IsAlreadyExists(err) {
    28  				return err
    29  			}
    30  		}
    31  	}
    32  	// apply everything else
    33  	for _, manifest := range manifests {
    34  		if manifest.GetKind() != "Namespace" {
    35  			if err := c.Create(ctx, manifest); err != nil && !errors.IsAlreadyExists(err) {
    36  				return err
    37  			}
    38  		}
    39  	}
    40  
    41  	return nil
    42  }
    43  

View as plain text