github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/cmd/reconcile.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/caos/orbos/internal/operator/boom/api/latest" 7 "github.com/caos/orbos/mntr" 8 "github.com/caos/orbos/pkg/kubernetes" 9 "github.com/caos/orbos/pkg/kubernetes/k8s" 10 "github.com/caos/orbos/pkg/labels" 11 corev1 "k8s.io/api/core/v1" 12 "k8s.io/apimachinery/pkg/api/resource" 13 ) 14 15 func Reconcile( 16 monitor mntr.Monitor, 17 apiLabels *labels.API, 18 k8sClient kubernetes.ClientInt, 19 boomSpec *latest.Boom, 20 binaryVersion string, 21 gitops bool, 22 ) error { 23 24 resources := k8s.Resources(corev1.ResourceRequirements{ 25 Limits: corev1.ResourceList{ 26 corev1.ResourceCPU: resource.MustParse("250m"), 27 corev1.ResourceMemory: resource.MustParse("512Mi"), 28 }, 29 Requests: corev1.ResourceList{ 30 corev1.ResourceCPU: resource.MustParse("100m"), 31 corev1.ResourceMemory: resource.MustParse("256Mi"), 32 }, 33 }) 34 35 imageRegistry := "ghcr.io" 36 var boomVersion string 37 var nodeselector map[string]string 38 var tolerations k8s.Tolerations 39 40 if boomSpec != nil { 41 if boomSpec.Version != "" { 42 boomVersion = boomSpec.Version 43 } 44 if boomSpec.Resources != nil { 45 resources = *boomSpec.Resources 46 } 47 if boomSpec.NodeSelector != nil { 48 nodeselector = boomSpec.NodeSelector 49 } 50 if boomSpec.Tolerations != nil { 51 tolerations = boomSpec.Tolerations 52 } 53 if boomSpec.CustomImageRegistry != "" { 54 imageRegistry = boomSpec.CustomImageRegistry 55 } 56 } 57 if boomVersion == "" { 58 monitor.Info(fmt.Sprintf("No version set in boom.yml, so current binary version %s will get applied", binaryVersion)) 59 boomVersion = binaryVersion 60 } 61 62 recMonitor := monitor.WithField("version", boomVersion) 63 64 if err := kubernetes.EnsureBoomArtifacts(monitor, apiLabels, k8sClient, boomVersion, tolerations, nodeselector, &resources, imageRegistry, gitops); err != nil { 65 return fmt.Errorf("failed to deploy boom into k8s-cluster: %w", err) 66 } 67 68 recMonitor.Info("Applied BOOM") 69 70 return nil 71 }