diff --git a/api/v1/coroot_types.go b/api/v1/coroot_types.go index 6b660b9..23d8206 100644 --- a/api/v1/coroot_types.go +++ b/api/v1/coroot_types.go @@ -85,6 +85,10 @@ type ExternalClickhouseSpec struct { Database string `json:"database,omitempty"` } +type PostgresSpec struct { + ConnectionString string `json:"connectionString,omitempty"` +} + type CorootSpec struct { ApiKey string `json:"apiKey,omitempty"` MetricsRefreshInterval metav1.Duration `json:"metricsRefreshInterval,omitempty"` @@ -97,8 +101,8 @@ type CorootSpec struct { EnterpriseEdition *EnterpriseEditionSpec `json:"enterpriseEdition,omitempty"` AgentsOnly *AgentsOnlySpec `json:"agentsOnly,omitempty"` - Service ServiceSpec `json:"service,omitempty"` - + Replicas int `json:"replicas,omitempty"` + Service ServiceSpec `json:"service,omitempty"` Affinity *corev1.Affinity `json:"affinity,omitempty"` Storage StorageSpec `json:"storage,omitempty"` Resources corev1.ResourceRequirements `json:"resources,omitempty"` @@ -110,6 +114,8 @@ type CorootSpec struct { Clickhouse ClickhouseSpec `json:"clickhouse,omitempty"` ExternalClickhouse *ExternalClickhouseSpec `json:"externalClickhouse,omitempty"` + + Postgres *PostgresSpec `json:"postgres,omitempty"` } type CorootStatus struct { // TODO diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index f66e260..d8a1ec3 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -212,6 +212,11 @@ func (in *CorootSpec) DeepCopyInto(out *CorootSpec) { *out = new(ExternalClickhouseSpec) **out = **in } + if in.Postgres != nil { + in, out := &in.Postgres, &out.Postgres + *out = new(PostgresSpec) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CorootSpec. @@ -305,6 +310,21 @@ func (in *NodeAgentSpec) DeepCopy() *NodeAgentSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PostgresSpec) DeepCopyInto(out *PostgresSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostgresSpec. +func (in *PostgresSpec) DeepCopy() *PostgresSpec { + if in == nil { + return nil + } + out := new(PostgresSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PrometheusSpec) DeepCopyInto(out *PrometheusSpec) { *out = *in diff --git a/config/crd/coroot.com_coroots.yaml b/config/crd/coroot.com_coroots.yaml index 0a6b185..30cb2d5 100644 --- a/config/crd/coroot.com_coroots.yaml +++ b/config/crd/coroot.com_coroots.yaml @@ -5405,6 +5405,11 @@ spec: version: type: string type: object + postgres: + properties: + connectionString: + type: string + type: object prometheus: properties: affinity: @@ -6406,6 +6411,8 @@ spec: x-kubernetes-int-or-string: true type: object type: object + replicas: + type: integer resources: description: ResourceRequirements describes the compute resource requirements. properties: diff --git a/config/samples/coroot.yaml b/config/samples/coroot.yaml index 2cbbe3f..d91a200 100644 --- a/config/samples/coroot.yaml +++ b/config/samples/coroot.yaml @@ -9,6 +9,7 @@ spec: # licenseKey: # agentsOnly: # corootUrl: +# replicas: 1 nodeAgent: clusterAgent: prometheus: diff --git a/controller/clickhouse_keeper.go b/controller/clickhouse_keeper.go index 0290e4c..ebdf614 100644 --- a/controller/clickhouse_keeper.go +++ b/controller/clickhouse_keeper.go @@ -87,10 +87,6 @@ func (r *CorootReconciler) clickhouseKeeperStatefulSet(cr *corootv1.Coroot) *app } replicas := int32(ClickhouseKeeperReplicas) - storageSize := cr.Spec.Clickhouse.Keeper.Storage.Size - if storageSize.IsZero() { - storageSize, _ = resource.ParseQuantity("10Gi") - } ss.Spec = appsv1.StatefulSetSpec{ Selector: &metav1.LabelSelector{ MatchLabels: ls, diff --git a/controller/controller.go b/controller/controller.go index 54f829c..9ed634a 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -15,7 +15,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/log" "sync" "time" ) @@ -34,6 +33,8 @@ type CorootReconciler struct { versions map[App]string versionsLock sync.Mutex + + deploymentDeleted bool } func NewCorootReconciler(mgr ctrl.Manager) *CorootReconciler { @@ -75,21 +76,23 @@ func NewCorootReconciler(mgr ctrl.Manager) *CorootReconciler { // +kubebuilder:rbac:groups=security.openshift.io,resources=securitycontextconstraints,verbs=use func (r *CorootReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - logger := log.FromContext(ctx) + logger := ctrl.Log.WithValues("namespace", req.Namespace, "name", req.Name) cr := &corootv1.Coroot{} err := r.Get(ctx, req.NamespacedName, cr) if err != nil { if errors.IsNotFound(err) { - logger.Info("Coroot has been deleted") r.instancesLock.Lock() - delete(r.instances, req) + if r.instances[req] { + logger.Info("Coroot has been deleted") + delete(r.instances, req) + cr = &corootv1.Coroot{} + cr.Name = req.Name + cr.Namespace = req.Namespace + _ = r.Delete(ctx, r.clusterAgentClusterRoleBinding(cr)) + _ = r.Delete(ctx, r.clusterAgentClusterRole(cr)) + } r.instancesLock.Unlock() - cr = &corootv1.Coroot{} - cr.Name = req.Name - cr.Namespace = req.Namespace - _ = r.Delete(ctx, r.clusterAgentClusterRoleBinding(cr)) - _ = r.Delete(ctx, r.clusterAgentClusterRole(cr)) return ctrl.Result{}, nil } return ctrl.Result{}, err @@ -114,10 +117,20 @@ func (r *CorootReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr return ctrl.Result{}, nil } + if cr.Spec.Replicas > 1 && (cr.Spec.Postgres == nil || cr.Spec.Postgres.ConnectionString == "") { + logger.Error(fmt.Errorf("Postgres.ConnectionString is empty"), "Coroot requires Postgres to run multiple replicas (will run only one replica)") + cr.Spec.Replicas = 1 + } r.CreateOrUpdateServiceAccount(ctx, cr, "coroot", sccNonroot) - r.CreateOrUpdatePVC(ctx, cr, r.corootPVC(cr)) - r.CreateOrUpdateDeployment(ctx, cr, r.corootDeployment(cr)) + for _, pvc := range r.corootPVCs(cr) { + r.CreateOrUpdatePVC(ctx, cr, pvc) + } + r.CreateOrUpdateStatefulSet(ctx, cr, r.corootStatefulSet(cr)) r.CreateOrUpdateService(ctx, cr, r.corootService(cr)) + if !r.deploymentDeleted { + _ = r.Delete(ctx, r.corootDeployment(cr)) + r.deploymentDeleted = true + } r.CreateOrUpdateServiceAccount(ctx, cr, "prometheus", sccNonroot) r.CreateOrUpdatePVC(ctx, cr, r.prometheusPVC(cr)) @@ -128,11 +141,11 @@ func (r *CorootReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr r.CreateSecret(ctx, cr, r.clickhouseSecret(cr)) r.CreateOrUpdateServiceAccount(ctx, cr, "clickhouse-keeper", sccNonroot) + r.CreateOrUpdateService(ctx, cr, r.clickhouseKeeperServiceHeadless(cr)) for _, pvc := range r.clickhouseKeeperPVCs(cr) { r.CreateOrUpdatePVC(ctx, cr, pvc) } r.CreateOrUpdateStatefulSet(ctx, cr, r.clickhouseKeeperStatefulSet(cr)) - r.CreateOrUpdateService(ctx, cr, r.clickhouseKeeperServiceHeadless(cr)) r.CreateOrUpdateServiceAccount(ctx, cr, "clickhouse", sccNonroot) r.CreateOrUpdateService(ctx, cr, r.clickhouseServiceHeadless(cr)) @@ -151,7 +164,7 @@ func (r *CorootReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr } func (r *CorootReconciler) CreateOrUpdate(ctx context.Context, cr *corootv1.Coroot, obj client.Object, f controllerutil.MutateFn) { - logger := log.FromContext(nil, "type", fmt.Sprintf("%T", obj), "name", obj.GetName(), "namespace", obj.GetNamespace()) + logger := ctrl.Log.WithValues("type", fmt.Sprintf("%T", obj), "name", obj.GetName(), "namespace", obj.GetNamespace()) _ = ctrl.SetControllerReference(cr, obj, r.Scheme) errMsg := "failed to create or update" if f == nil { diff --git a/controller/coroot.go b/controller/coroot.go index e05deff..516d915 100644 --- a/controller/coroot.go +++ b/controller/coroot.go @@ -43,6 +43,41 @@ func (r *CorootReconciler) corootService(cr *corootv1.Coroot) *corev1.Service { return s } +func (r *CorootReconciler) corootPVCs(cr *corootv1.Coroot) []*corev1.PersistentVolumeClaim { + ls := Labels(cr, "coroot") + + size := cr.Spec.Storage.Size + if size.IsZero() { + size, _ = resource.ParseQuantity("10Gi") + } + replicas := cr.Spec.Replicas + if replicas == 0 { + replicas = 1 + } + + var res []*corev1.PersistentVolumeClaim + for replica := 0; replica < replicas; replica++ { + pvc := &corev1.PersistentVolumeClaim{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("data-%s-coroot-%d", cr.Name, replica), + Namespace: cr.Namespace, + Labels: ls, + }, + Spec: corev1.PersistentVolumeClaimSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, + Resources: corev1.VolumeResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceStorage: size, + }, + }, + StorageClassName: cr.Spec.Storage.ClassName, + }, + } + res = append(res, pvc) + } + return res +} + func (r *CorootReconciler) corootDeployment(cr *corootv1.Coroot) *appsv1.Deployment { ls := Labels(cr, "coroot") d := &appsv1.Deployment{ @@ -52,6 +87,18 @@ func (r *CorootReconciler) corootDeployment(cr *corootv1.Coroot) *appsv1.Deploym Labels: ls, }, } + return d +} + +func (r *CorootReconciler) corootStatefulSet(cr *corootv1.Coroot) *appsv1.StatefulSet { + ls := Labels(cr, "coroot") + ss := &appsv1.StatefulSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: cr.Name + "-coroot", + Namespace: cr.Namespace, + Labels: ls, + }, + } refreshInterval := cr.Spec.MetricsRefreshInterval.Duration.String() if cr.Spec.MetricsRefreshInterval.Duration == 0 { @@ -61,7 +108,6 @@ func (r *CorootReconciler) corootDeployment(cr *corootv1.Coroot) *appsv1.Deploym env := []corev1.EnvVar{ {Name: "GLOBAL_REFRESH_INTERVAL", Value: refreshInterval}, {Name: "GLOBAL_PROMETHEUS_URL", Value: fmt.Sprintf("http://%s-prometheus.%s:9090", cr.Name, cr.Namespace)}, - {Name: "DO_NOT_CHECK_FOR_UPDATES", Value: "1"}, {Name: "INSTALLATION_TYPE", Value: "k8s-operator"}, } if cr.Spec.CacheTTL.Duration > 0 { @@ -111,13 +157,26 @@ func (r *CorootReconciler) corootDeployment(cr *corootv1.Coroot) *appsv1.Deploym ) } - d.Spec = appsv1.DeploymentSpec{ + if cr.Spec.Postgres != nil && cr.Spec.Postgres.ConnectionString != "" { + env = append(env, corev1.EnvVar{Name: "PG_CONNECTION_STRING", Value: cr.Spec.Postgres.ConnectionString}) + } + + replicas := int32(cr.Spec.Replicas) + if replicas <= 0 { + replicas = 1 + } + + ss.Spec = appsv1.StatefulSetSpec{ Selector: &metav1.LabelSelector{ MatchLabels: ls, }, - Strategy: appsv1.DeploymentStrategy{ - Type: appsv1.RecreateDeploymentStrategyType, - }, + Replicas: &replicas, + VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ + ObjectMeta: metav1.ObjectMeta{ + Name: "data", + Namespace: cr.Namespace, + }, + }}, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: ls, @@ -149,45 +208,9 @@ func (r *CorootReconciler) corootDeployment(cr *corootv1.Coroot) *appsv1.Deploym }, }, }, - Volumes: []corev1.Volume{ - { - Name: "data", - VolumeSource: corev1.VolumeSource{ - PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ - ClaimName: "data-" + cr.Name + "-coroot", - }, - }, - }, - }, - }, - }, - } - - return d -} - -func (r *CorootReconciler) corootPVC(cr *corootv1.Coroot) *corev1.PersistentVolumeClaim { - pvc := &corev1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{ - Name: "data-" + cr.Name + "-coroot", - Namespace: cr.Namespace, - Labels: Labels(cr, "coroot"), - }, - } - - size := cr.Spec.Storage.Size - if size.IsZero() { - size, _ = resource.ParseQuantity("10Gi") - } - pvc.Spec = corev1.PersistentVolumeClaimSpec{ - AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, - Resources: corev1.VolumeResourceRequirements{ - Requests: corev1.ResourceList{ - corev1.ResourceStorage: size, }, }, - StorageClassName: cr.Spec.Storage.ClassName, } - return pvc + return ss } diff --git a/controller/node_agent.go b/controller/node_agent.go index 4f47c96..b440fdd 100644 --- a/controller/node_agent.go +++ b/controller/node_agent.go @@ -5,6 +5,7 @@ import ( corootv1 "github.io/coroot/operator/api/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" ) @@ -35,6 +36,21 @@ func (r *CorootReconciler) nodeAgentDaemonSet(cr *corootv1.Coroot) *appsv1.Daemo for _, e := range cr.Spec.NodeAgent.Env { env = append(env, e) } + + resources := cr.Spec.NodeAgent.Resources + if resources.Requests == nil { + resources.Requests = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("100m"), + corev1.ResourceMemory: resource.MustParse("200Mi"), + } + } + if resources.Limits == nil { + resources.Limits = corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("500m"), + corev1.ResourceMemory: resource.MustParse("1Gi"), + } + } + ds.Spec = appsv1.DaemonSetSpec{ Selector: &metav1.LabelSelector{ MatchLabels: ls, @@ -59,7 +75,7 @@ func (r *CorootReconciler) nodeAgentDaemonSet(cr *corootv1.Coroot) *appsv1.Daemo }, SecurityContext: &corev1.SecurityContext{Privileged: ptr.To(true)}, Env: env, - Resources: cr.Spec.NodeAgent.Resources, + Resources: resources, VolumeMounts: []corev1.VolumeMount{ {Name: "cgroupfs", MountPath: "/host/sys/fs/cgroup", ReadOnly: true}, {Name: "tracefs", MountPath: "/sys/kernel/tracing"}, diff --git a/controller/utils.go b/controller/utils.go index 8451322..a39a581 100644 --- a/controller/utils.go +++ b/controller/utils.go @@ -3,7 +3,7 @@ package controller import ( "crypto/rand" "encoding/json" - "github.com/pkg/errors" + "fmt" "k8s.io/apimachinery/pkg/util/strategicpatch" "math/big" "reflect" @@ -25,35 +25,35 @@ func GeneratePassword(length int) string { func Merge[T any](base *T, overrides T) error { baseBytes, err := json.Marshal(base) if err != nil { - return errors.Wrap(err, "failed to convert current object to byte sequence") + return fmt.Errorf("failed to marshal base: %w", err) } overrideBytes, err := json.Marshal(overrides) if err != nil { - return errors.Wrap(err, "failed to convert current object to byte sequence") + return fmt.Errorf("failed to marshal overrides: %w", err) } patchMeta, err := strategicpatch.NewPatchMetaFromStruct(base) if err != nil { - return errors.Wrap(err, "failed to produce patch meta from struct") + return fmt.Errorf("failed to produce patch meta from struct: %w", err) } patch, err := strategicpatch.CreateThreeWayMergePatch(overrideBytes, overrideBytes, baseBytes, patchMeta, true) if err != nil { - return errors.Wrap(err, "failed to create three way merge patch") + return fmt.Errorf("failed to create three way merge patch: %w", err) } merged, err := strategicpatch.StrategicMergePatchUsingLookupPatchMeta(baseBytes, patch, patchMeta) if err != nil { - return errors.Wrap(err, "failed to apply patch") + return fmt.Errorf("failed to apply patch: %w", err) } valueOfBase := reflect.Indirect(reflect.ValueOf(base)) into := reflect.New(valueOfBase.Type()) - if err := json.Unmarshal(merged, into.Interface()); err != nil { - return err + if err = json.Unmarshal(merged, into.Interface()); err != nil { + return fmt.Errorf("failed to unmarshal merged data: %w", err) } if !valueOfBase.CanSet() { - return errors.New("unable to set unmarshalled value into base object") + return fmt.Errorf("unable to set unmarshalled value into base object") } valueOfBase.Set(reflect.Indirect(into)) return nil diff --git a/go.mod b/go.mod index a66b554..a6182a5 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.io/coroot/operator go 1.23 require ( - github.com/pkg/errors v0.9.1 + golang.org/x/exp v0.0.0-20241210194714-1829a127f884 k8s.io/api v0.31.1 k8s.io/apimachinery v0.31.1 k8s.io/client-go v0.31.1 - k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3 - sigs.k8s.io/controller-runtime v0.19.0 + k8s.io/utils v0.0.0-20241210054802-24370beab758 + sigs.k8s.io/controller-runtime v0.19.3 ) require ( @@ -18,7 +18,6 @@ require ( github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/zapr v1.3.0 // indirect @@ -41,6 +40,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/onsi/ginkgo/v2 v2.20.2 // indirect github.com/onsi/gomega v1.34.2 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.19.1 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.55.0 // indirect @@ -49,7 +49,6 @@ require ( github.com/x448/float16 v0.8.4 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.26.0 // indirect - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sys v0.25.0 // indirect diff --git a/go.sum b/go.sum index 50a087c..fa69077 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,6 @@ github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= @@ -115,8 +113,8 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/exp v0.0.0-20241210194714-1829a127f884 h1:Y/Mj/94zIQQGHVSv1tTtQBDaQaJe62U9bkDZKKyhPCU= +golang.org/x/exp v0.0.0-20241210194714-1829a127f884/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -147,8 +145,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= +golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -182,10 +180,10 @@ k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag= k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98= -k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3 h1:b2FmK8YH+QEwq/Sy2uAEhmqL5nPfGYbJOcaqjeYYZoA= -k8s.io/utils v0.0.0-20240902221715-702e33fdd3c3/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -sigs.k8s.io/controller-runtime v0.19.0 h1:nWVM7aq+Il2ABxwiCizrVDSlmDcshi9llbaFbC0ji/Q= -sigs.k8s.io/controller-runtime v0.19.0/go.mod h1:iRmWllt8IlaLjvTTDLhRBXIEtkCK6hwVBJJsYS9Ajf4= +k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0= +k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +sigs.k8s.io/controller-runtime v0.19.3 h1:XO2GvC9OPftRst6xWCpTgBZO04S2cbp0Qqkj8bX1sPw= +sigs.k8s.io/controller-runtime v0.19.3/go.mod h1:j4j87DqtsThvwTv5/Tc5NFRyyF/RF0ip4+62tbTSIUM= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= diff --git a/main.go b/main.go index ce2c8de..3e045ca 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "github.io/coroot/operator/controller" + "go.uber.org/zap/zapcore" "os" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) @@ -20,8 +21,7 @@ import ( ) var ( - scheme = runtime.NewScheme() - setupLog = ctrl.Log.WithName("setup") + scheme = runtime.NewScheme() ) func init() { @@ -32,7 +32,8 @@ func init() { } func main() { - ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zap.Options{Development: true}))) + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zap.Options{Development: true, StacktraceLevel: zapcore.DPanicLevel}))) + logger := ctrl.Log mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, @@ -40,30 +41,30 @@ func main() { HealthProbeBindAddress: ":8081", }) if err != nil { - setupLog.Error(err, "unable to start manager") + logger.Error(err, "failed to start manager") os.Exit(1) } reconciler := controller.NewCorootReconciler(mgr) if err = reconciler.SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller") + logger.Error(err, "failed to create controller") os.Exit(1) } // +kubebuilder:scaffold:builder if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { - setupLog.Error(err, "unable to set up health check") + logger.Error(err, "failed to set up health check") os.Exit(1) } if err = mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { - setupLog.Error(err, "unable to set up ready check") + logger.Error(err, "failed to set up ready check") os.Exit(1) } - setupLog.Info("starting manager") + logger.Info("starting manager") if err = mgr.Start(ctrl.SetupSignalHandler()); err != nil { - setupLog.Error(err, "problem running manager") + logger.Error(err, "failed to start manager") os.Exit(1) } }