From 373d5f2efe498487d4b1e4de538cb048ca757f63 Mon Sep 17 00:00:00 2001 From: Pete Savage Date: Thu, 25 Nov 2021 13:19:57 +0000 Subject: [PATCH] Fixed a number of standards issues --- .../v1alpha1/clowdenvironment_types.go | 2 +- .../cloud.redhat.com/clowdapp_controller.go | 5 +- .../clowdenvironment_controller.go | 4 +- .../config.go | 2 +- .../config_test.go | 2 +- .../test_config.json | 0 .../clowdjobinvocation_controller.go | 225 +++++++++--------- controllers/cloud.redhat.com/object/object.go | 2 +- controllers/cloud.redhat.com/pod_mutator.go | 10 +- .../providers/autoscaler/default.go | 4 +- .../providers/cronjob/provider.go | 2 +- .../providers/database/shareddb.go | 4 +- .../providers/kafka/strimzi.go | 7 +- .../providers/metrics/appinterface.go | 4 +- .../providers/metrics/operator.go | 4 +- .../providers/resource_cache.go | 12 +- .../cloud.redhat.com/providers/web/impl.go | 10 +- .../cloud.redhat.com/providers/web/local.go | 6 +- controllers/cloud.redhat.com/run.go | 4 +- controllers/cloud.redhat.com/status.go | 44 ++-- main.go | 6 +- 21 files changed, 179 insertions(+), 180 deletions(-) rename controllers/cloud.redhat.com/{clowder_config => clowderconfig}/config.go (98%) rename controllers/cloud.redhat.com/{clowder_config => clowderconfig}/config_test.go (95%) rename controllers/cloud.redhat.com/{clowder_config => clowderconfig}/test_config.json (100%) diff --git a/apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go b/apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go index 81eb8390c..341597d91 100644 --- a/apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go +++ b/apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go @@ -646,7 +646,7 @@ func (i *ClowdEnvironment) GetNamespacesInEnv(ctx context.Context, pClient clien namespaceList := []string{} - for namespace, _ := range tmpNamespace { + for namespace := range tmpNamespace { namespaceList = append(namespaceList, namespace) } diff --git a/controllers/cloud.redhat.com/clowdapp_controller.go b/controllers/cloud.redhat.com/clowdapp_controller.go index 3ca687665..a12eddf25 100644 --- a/controllers/cloud.redhat.com/clowdapp_controller.go +++ b/controllers/cloud.redhat.com/clowdapp_controller.go @@ -45,7 +45,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/source" // Import the providers to initialize them - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" @@ -279,7 +280,7 @@ func ignoreStatusUpdatePredicate(logr logr.Logger, ctrlName string) predicate.Pr logr.Info("Reconciliation trigger", "ctrl", ctrlName, "type", "update", "resType", gvk.Kind, "name", e.ObjectOld.GetName(), "namespace", e.ObjectOld.GetNamespace()) - if clowder_config.LoadedConfig.DebugOptions.Trigger.Diff { + if clowderconfig.LoadedConfig.DebugOptions.Trigger.Diff { if e.ObjectNew.GetObjectKind().GroupVersionKind() == secretCompare { logr.Info("Trigger diff", "diff", "hidden", "ctrl", ctrlName, "type", "update", "resType", gvk.Kind, "name", e.ObjectOld.GetName(), "namespace", e.ObjectOld.GetNamespace()) } else { diff --git a/controllers/cloud.redhat.com/clowdenvironment_controller.go b/controllers/cloud.redhat.com/clowdenvironment_controller.go index 1abb93984..cdea1d0ac 100644 --- a/controllers/cloud.redhat.com/clowdenvironment_controller.go +++ b/controllers/cloud.redhat.com/clowdenvironment_controller.go @@ -60,7 +60,7 @@ import ( "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/utils" crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" k8serr "k8s.io/apimachinery/pkg/api/errors" @@ -304,7 +304,7 @@ func (r *ClowdEnvironmentReconciler) SetupWithManager(mgr ctrl.Manager) error { ). For(&crd.ClowdEnvironment{}) - if clowder_config.LoadedConfig.Features.WatchStrimziResources { + if clowderconfig.LoadedConfig.Features.WatchStrimziResources { ctrlr.Owns(&strimzi.Kafka{}) ctrlr.Owns(&strimzi.KafkaConnect{}) ctrlr.Owns(&strimzi.KafkaUser{}) diff --git a/controllers/cloud.redhat.com/clowder_config/config.go b/controllers/cloud.redhat.com/clowderconfig/config.go similarity index 98% rename from controllers/cloud.redhat.com/clowder_config/config.go rename to controllers/cloud.redhat.com/clowderconfig/config.go index a1c06c05e..04534dde3 100644 --- a/controllers/cloud.redhat.com/clowder_config/config.go +++ b/controllers/cloud.redhat.com/clowderconfig/config.go @@ -1,4 +1,4 @@ -package clowder_config +package clowderconfig import ( "encoding/json" diff --git a/controllers/cloud.redhat.com/clowder_config/config_test.go b/controllers/cloud.redhat.com/clowderconfig/config_test.go similarity index 95% rename from controllers/cloud.redhat.com/clowder_config/config_test.go rename to controllers/cloud.redhat.com/clowderconfig/config_test.go index f809e0844..2ff85b5a9 100644 --- a/controllers/cloud.redhat.com/clowder_config/config_test.go +++ b/controllers/cloud.redhat.com/clowderconfig/config_test.go @@ -1,4 +1,4 @@ -package clowder_config +package clowderconfig import ( "encoding/json" diff --git a/controllers/cloud.redhat.com/clowder_config/test_config.json b/controllers/cloud.redhat.com/clowderconfig/test_config.json similarity index 100% rename from controllers/cloud.redhat.com/clowder_config/test_config.json rename to controllers/cloud.redhat.com/clowderconfig/test_config.json diff --git a/controllers/cloud.redhat.com/clowdjobinvocation_controller.go b/controllers/cloud.redhat.com/clowdjobinvocation_controller.go index db3a8ff2e..254ed8b1e 100644 --- a/controllers/cloud.redhat.com/clowdjobinvocation_controller.go +++ b/controllers/cloud.redhat.com/clowdjobinvocation_controller.go @@ -112,146 +112,145 @@ func (r *ClowdJobInvocationReconciler) Reconcile(ctx context.Context, req ctrl.R return ctrl.Result{}, condErr } return ctrl.Result{}, nil - } else { - // This is a fresh CJI and needs to be invoked the first time - r.Log.Info("Reconciliation started", "ClowdJobInvocation", fmt.Sprintf("%s:%s", cji.Namespace, cji.Name)) - ctx = context.WithValue(ctx, errors.ClowdKey("obj"), &cji) - - // Get the ClowdApp. Used to find definition of job being invoked - app := crd.ClowdApp{} - appErr := r.Client.Get(ctx, types.NamespacedName{ - Name: cji.Spec.AppName, - Namespace: req.Namespace, - }, &app) - - // Set the base map here so we can update the status on errors - cji.Status.JobMap = map[string]crd.JobConditionState{} + } + // This is a fresh CJI and needs to be invoked the first time + r.Log.Info("Reconciliation started", "ClowdJobInvocation", fmt.Sprintf("%s:%s", cji.Namespace, cji.Name)) + ctx = context.WithValue(ctx, errors.ClowdKey("obj"), &cji) + + // Get the ClowdApp. Used to find definition of job being invoked + app := crd.ClowdApp{} + appErr := r.Client.Get(ctx, types.NamespacedName{ + Name: cji.Spec.AppName, + Namespace: req.Namespace, + }, &app) + + // Set the base map here so we can update the status on errors + cji.Status.JobMap = map[string]crd.JobConditionState{} + + // Determine if the ClowdApp containing the Job exists + if appErr != nil { + r.Recorder.Eventf(&cji, "Warning", "ClowdAppMissing", "ClowdApp [%s] is missing; Job cannot be invoked", cji.Spec.AppName) + r.Log.Error(appErr, "App not found", "ClowdApp", cji.Spec.AppName, "namespace", cji.Namespace) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, appErr); condErr != nil { + return ctrl.Result{}, condErr + } + // requeue with a buffer to let the app come up + return ctrl.Result{Requeue: true}, appErr + } - // Determine if the ClowdApp containing the Job exists - if appErr != nil { - r.Recorder.Eventf(&cji, "Warning", "ClowdAppMissing", "ClowdApp [%s] is missing; Job cannot be invoked", cji.Spec.AppName) - r.Log.Error(appErr, "App not found", "ClowdApp", cji.Spec.AppName, "namespace", cji.Namespace) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, appErr); condErr != nil { - return ctrl.Result{}, condErr - } - // requeue with a buffer to let the app come up - return ctrl.Result{Requeue: true}, appErr + // Determine if the ClowdApp containing the Job is ready + if !app.IsReady() { + r.Recorder.Eventf(&app, "Warning", "ClowdAppNotReady", "ClowdApp [%s] is not ready", cji.Spec.AppName) + r.Log.Info("App not yet ready, requeue", "jobinvocation", cji.Spec.AppName, "namespace", app.Namespace) + readyErr := errors.New(fmt.Sprintf("The %s app must be ready for CJI to start", cji.Spec.AppName)) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, readyErr); condErr != nil { + return ctrl.Result{}, condErr } - // Determine if the ClowdApp containing the Job is ready - if !app.IsReady() { - r.Recorder.Eventf(&app, "Warning", "ClowdAppNotReady", "ClowdApp [%s] is not ready", cji.Spec.AppName) - r.Log.Info("App not yet ready, requeue", "jobinvocation", cji.Spec.AppName, "namespace", app.Namespace) - readyErr := errors.New(fmt.Sprintf("The %s app must be ready for CJI to start", cji.Spec.AppName)) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, readyErr); condErr != nil { - return ctrl.Result{}, condErr - } + // requeue with a buffer to let the app come up + return ctrl.Result{Requeue: true}, readyErr + } - // requeue with a buffer to let the app come up - return ctrl.Result{Requeue: true}, readyErr - } + // Get the ClowdEnv for InvokeJob. Env is needed to build out our pod + // template for each job + env := crd.ClowdEnvironment{} + envErr := r.Client.Get(ctx, types.NamespacedName{ + Name: app.Spec.EnvName, + }, &env) - // Get the ClowdEnv for InvokeJob. Env is needed to build out our pod - // template for each job - env := crd.ClowdEnvironment{} - envErr := r.Client.Get(ctx, types.NamespacedName{ - Name: app.Spec.EnvName, - }, &env) + if envErr != nil { + r.Recorder.Eventf(&cji, "Warning", "ClowdEnvMissing", "ClowdEnv [%s] is missing; Job cannot be invoked", app.Spec.EnvName) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, envErr); condErr != nil { + return ctrl.Result{}, condErr + } + // requeue with a buffer to let the env come up + return ctrl.Result{Requeue: true}, envErr + } - if envErr != nil { - r.Recorder.Eventf(&cji, "Warning", "ClowdEnvMissing", "ClowdEnv [%s] is missing; Job cannot be invoked", app.Spec.EnvName) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, envErr); condErr != nil { + // Walk the job names to be invoked and match in the ClowdApp Spec + for _, jobName := range cji.Spec.Jobs { + // Match the crd.Job name to the JobTemplate in ClowdApp + job, err := getJobFromName(jobName, &app) + if err != nil { + r.Recorder.Eventf(&app, "Warning", "JobNameMissing", "ClowdApp [%s] has no job defined for that name", jobName) + r.Log.Info("Missing Job Definition", "jobinvocation", cji.Spec.AppName, "namespace", app.Namespace) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { return ctrl.Result{}, condErr } - // requeue with a buffer to let the env come up - return ctrl.Result{Requeue: true}, envErr + return ctrl.Result{}, err } + job.Name = fmt.Sprintf("%s-%s", app.Name, jobName) - // Walk the job names to be invoked and match in the ClowdApp Spec - for _, jobName := range cji.Spec.Jobs { - // Match the crd.Job name to the JobTemplate in ClowdApp - job, err := getJobFromName(jobName, &app) - if err != nil { - r.Recorder.Eventf(&app, "Warning", "JobNameMissing", "ClowdApp [%s] has no job defined for that name", jobName) - r.Log.Info("Missing Job Definition", "jobinvocation", cji.Spec.AppName, "namespace", app.Namespace) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { - return ctrl.Result{}, condErr - } - return ctrl.Result{}, err - } - job.Name = fmt.Sprintf("%s-%s", app.Name, jobName) - - // We have a match that isn't running and can invoke the job - r.Log.Info("Invoking job", "jobinvocation", job.Name, "namespace", app.Namespace) + // We have a match that isn't running and can invoke the job + r.Log.Info("Invoking job", "jobinvocation", job.Name, "namespace", app.Namespace) - if err := r.InvokeJob(ctx, &cache, &job, &app, &env, &cji); err != nil { - r.Log.Error(err, "Job Invocation Failed", "jobinvocation", jobName, "namespace", app.Namespace) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { - return ctrl.Result{}, condErr - } - r.Recorder.Eventf(&cji, "Warning", "JobNotInvoked", "Job [%s] could not be invoked", jobName) - return ctrl.Result{Requeue: true}, err + if err := r.InvokeJob(ctx, &cache, &job, &app, &env, &cji); err != nil { + r.Log.Error(err, "Job Invocation Failed", "jobinvocation", jobName, "namespace", app.Namespace) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { + return ctrl.Result{}, condErr } + r.Recorder.Eventf(&cji, "Warning", "JobNotInvoked", "Job [%s] could not be invoked", jobName) + return ctrl.Result{Requeue: true}, err } + } - // Check IQE struct to see if we need to invoke an IQE Job - // In the future, we'll need to handle other types, but this will suffice since testing only has iqe. - var emptyTesting crd.IqeJobSpec - if cji.Spec.Testing.Iqe != emptyTesting { - - nn := types.NamespacedName{ - Name: cji.GenerateJobName(), - Namespace: cji.Namespace, - } + // Check IQE struct to see if we need to invoke an IQE Job + // In the future, we'll need to handle other types, but this will suffice since testing only has iqe. + var emptyTesting crd.IqeJobSpec + if cji.Spec.Testing.Iqe != emptyTesting { - j := batchv1.Job{} - if err := cache.Create(IqeClowdJob, nn, &j); err != nil { - r.Log.Error(err, "Iqe Job could not be created via cache", "jobinvocation", nn.Name) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { - return ctrl.Result{}, condErr - } - return ctrl.Result{}, err - } + nn := types.NamespacedName{ + Name: cji.GenerateJobName(), + Namespace: cji.Namespace, + } - if err := iqe.CreateIqeJobResource(&cache, &cji, &env, &app, nn, ctx, &j, r.Log, r.Client); err != nil { - r.Log.Error(err, "Iqe Job creation encountered an error", "jobinvocation", nn.Name) - r.Recorder.Eventf(&cji, "Warning", "IQEJobFailure", "Job [%s] failed to invoke", j.ObjectMeta.Name) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { - return ctrl.Result{}, condErr - } - return ctrl.Result{}, err + j := batchv1.Job{} + if err := cache.Create(IqeClowdJob, nn, &j); err != nil { + r.Log.Error(err, "Iqe Job could not be created via cache", "jobinvocation", nn.Name) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { + return ctrl.Result{}, condErr } + return ctrl.Result{}, err + } - if err := cache.Update(IqeClowdJob, &j); err != nil { - r.Log.Error(err, "Iqe Job could not update via cache", "jobinvocation", nn.Name) - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { - return ctrl.Result{}, condErr - } - return ctrl.Result{}, err - - } - r.Log.Info("Iqe Job Invoked Successfully", "jobinvocation", nn.Name, "namespace", app.Namespace) - if cji.Status.JobMap != nil { - cji.Status.JobMap[nn.Name] = crd.JobInvoked - } else { - cji.Status.JobMap = map[string]crd.JobConditionState{nn.Name: crd.JobInvoked} + if err := iqe.CreateIqeJobResource(&cache, &cji, &env, &app, nn, ctx, &j, r.Log, r.Client); err != nil { + r.Log.Error(err, "Iqe Job creation encountered an error", "jobinvocation", nn.Name) + r.Recorder.Eventf(&cji, "Warning", "IQEJobFailure", "Job [%s] failed to invoke", j.ObjectMeta.Name) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { + return ctrl.Result{}, condErr } - - r.Recorder.Eventf(&cji, "Normal", "IQEJobInvoked", "Job [%s] was invoked successfully", j.ObjectMeta.Name) + return ctrl.Result{}, err } - if cacheErr := cache.ApplyAll(); cacheErr != nil { - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationSuccessful, cacheErr); condErr != nil { + if err := cache.Update(IqeClowdJob, &j); err != nil { + r.Log.Error(err, "Iqe Job could not update via cache", "jobinvocation", nn.Name) + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationFailed, err); condErr != nil { return ctrl.Result{}, condErr } - return ctrl.Result{}, cacheErr + return ctrl.Result{}, err + + } + r.Log.Info("Iqe Job Invoked Successfully", "jobinvocation", nn.Name, "namespace", app.Namespace) + if cji.Status.JobMap != nil { + cji.Status.JobMap[nn.Name] = crd.JobInvoked + } else { + cji.Status.JobMap = map[string]crd.JobConditionState{nn.Name: crd.JobInvoked} } - // Short running jobs may be done by the time the loop is ranged, - // so we update again before the reconcile ends - if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationSuccessful, nil); condErr != nil { + r.Recorder.Eventf(&cji, "Normal", "IQEJobInvoked", "Job [%s] was invoked successfully", j.ObjectMeta.Name) + } + + if cacheErr := cache.ApplyAll(); cacheErr != nil { + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationSuccessful, cacheErr); condErr != nil { return ctrl.Result{}, condErr } + return ctrl.Result{}, cacheErr + } + + // Short running jobs may be done by the time the loop is ranged, + // so we update again before the reconcile ends + if condErr := SetClowdJobInvocationConditions(ctx, r.Client, &cji, crd.ReconciliationSuccessful, nil); condErr != nil { + return ctrl.Result{}, condErr } return ctrl.Result{}, nil diff --git a/controllers/cloud.redhat.com/object/object.go b/controllers/cloud.redhat.com/object/object.go index 4520b213d..c40bac706 100644 --- a/controllers/cloud.redhat.com/object/object.go +++ b/controllers/cloud.redhat.com/object/object.go @@ -16,7 +16,7 @@ type ClowdObject interface { GetPrimaryLabel() string } -// ClowdObject is used to be able to treat ClowdEnv and ClowdApp as the same type +// LabeledClowdObject is used to be able to treat ClowdEnv and ClowdApp as the same type type LabeledClowdObject interface { MakeOwnerReference() metav1.OwnerReference GetLabels() map[string]string diff --git a/controllers/cloud.redhat.com/pod_mutator.go b/controllers/cloud.redhat.com/pod_mutator.go index 13d3e9e2b..91ff52250 100644 --- a/controllers/cloud.redhat.com/pod_mutator.go +++ b/controllers/cloud.redhat.com/pod_mutator.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/utils" core "k8s.io/api/core/v1" "k8s.io/client-go/tools/record" @@ -50,8 +50,8 @@ func (p *mutantPod) Handle(ctx context.Context, req admission.Request) admission image := "quay.io/cloudservices/crc-caddy-plugin:a76bb81" - if clowder_config.LoadedConfig.Images.Caddy != "" { - image = clowder_config.LoadedConfig.Images.Caddy + if clowderconfig.LoadedConfig.Images.Caddy != "" { + image = clowderconfig.LoadedConfig.Images.Caddy } container := core.Container{ @@ -115,7 +115,7 @@ func (p *mutantPod) Handle(ctx context.Context, req admission.Request) admission return admission.PatchResponseFromRaw(req.Object.Raw, marshaledObj) } -func (a *mutantPod) InjectDecoder(d *admission.Decoder) error { - a.decoder = d +func (p *mutantPod) InjectDecoder(d *admission.Decoder) error { + p.decoder = d return nil } diff --git a/controllers/cloud.redhat.com/providers/autoscaler/default.go b/controllers/cloud.redhat.com/providers/autoscaler/default.go index 729b62b1d..463514885 100644 --- a/controllers/cloud.redhat.com/providers/autoscaler/default.go +++ b/controllers/cloud.redhat.com/providers/autoscaler/default.go @@ -11,10 +11,10 @@ type autoscalerProvider struct { p.Provider } -// CoreConfigSecret is the config that is presented as the cdappconfig.json file. +// CoreAutoScaler is the config that is presented as the cdappconfig.json file. var CoreAutoScaler = p.NewMultiResourceIdent(ProvName, "core_autoscaler", &keda.ScaledObject{}) -// NewConfigHashProvider returns a new End provider run at the end of the provider set. +// NewAutoScalerProvider returns a new End provider run at the end of the provider set. func NewAutoScalerProvider(p *p.Provider) (p.ClowderProvider, error) { return &autoscalerProvider{Provider: *p}, nil } diff --git a/controllers/cloud.redhat.com/providers/cronjob/provider.go b/controllers/cloud.redhat.com/providers/cronjob/provider.go index ecaa29e96..9619fd32b 100644 --- a/controllers/cloud.redhat.com/providers/cronjob/provider.go +++ b/controllers/cloud.redhat.com/providers/cronjob/provider.go @@ -11,7 +11,7 @@ var ProvName = "cronjob" // CoreCronJob is the croncronjob for the apps cronjobs. var CoreCronJob = p.NewMultiResourceIdent(ProvName, "core_cronjob", &batch.CronJob{}) -// GetEnd returns the correct end provider. +// GetCronJob returns the correct cronjob provider. func GetCronJob(c *p.Provider) (p.ClowderProvider, error) { return NewCronJobProvider(c) } diff --git a/controllers/cloud.redhat.com/providers/database/shareddb.go b/controllers/cloud.redhat.com/providers/database/shareddb.go index f9be7803f..428156923 100644 --- a/controllers/cloud.redhat.com/providers/database/shareddb.go +++ b/controllers/cloud.redhat.com/providers/database/shareddb.go @@ -9,7 +9,7 @@ import ( "database/sql" - _ "github.com/lib/pq" + _ "github.com/lib/pq" // Required to load postgres crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config" @@ -66,7 +66,7 @@ func NewSharedDBProvider(p *providers.Provider) (providers.ClowderProvider, erro configs := map[int32]*config.DatabaseConfig{} - for v, _ := range versionsRequired { + for v := range versionsRequired { dbCfg, err := createVersionedDatabase(p, v) if err != nil { return nil, err diff --git a/controllers/cloud.redhat.com/providers/kafka/strimzi.go b/controllers/cloud.redhat.com/providers/kafka/strimzi.go index 82b4dfa4c..4df2b4beb 100644 --- a/controllers/cloud.redhat.com/providers/kafka/strimzi.go +++ b/controllers/cloud.redhat.com/providers/kafka/strimzi.go @@ -10,7 +10,7 @@ import ( "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1/common" strimzi "github.com/RedHatInsights/strimzi-client-go/apis/kafka.strimzi.io/v1beta2" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" @@ -853,11 +853,10 @@ func (s *strimziProvider) processTopics(app *crd.ClowdApp) error { } func getTopicName(topic crd.KafkaTopicSpec, env crd.ClowdEnvironment, namespace string) string { - if clowder_config.LoadedConfig.Features.UseComplexStrimziTopicNames { + if clowderconfig.LoadedConfig.Features.UseComplexStrimziTopicNames { return fmt.Sprintf("%s-%s-%s", topic.TopicName, env.Name, namespace) - } else { - return topic.TopicName } + return topic.TopicName } func processTopicValues( diff --git a/controllers/cloud.redhat.com/providers/metrics/appinterface.go b/controllers/cloud.redhat.com/providers/metrics/appinterface.go index 991489ba0..8373ed89d 100644 --- a/controllers/cloud.redhat.com/providers/metrics/appinterface.go +++ b/controllers/cloud.redhat.com/providers/metrics/appinterface.go @@ -2,7 +2,7 @@ package metrics import ( crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config" p "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" ) @@ -21,7 +21,7 @@ func (m *appinterfaceMetricsProvider) Provide(app *crd.ClowdApp, c *config.AppCo return err } - if clowder_config.LoadedConfig.Features.CreateServiceMonitor { + if clowderconfig.LoadedConfig.Features.CreateServiceMonitor { if err := createServiceMonitorObjects(m.Cache, m.Env, app, c, "app-sre", "openshift-customer-monitoring"); err != nil { return err } diff --git a/controllers/cloud.redhat.com/providers/metrics/operator.go b/controllers/cloud.redhat.com/providers/metrics/operator.go index c54362219..70324f952 100644 --- a/controllers/cloud.redhat.com/providers/metrics/operator.go +++ b/controllers/cloud.redhat.com/providers/metrics/operator.go @@ -2,7 +2,7 @@ package metrics import ( crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/utils" @@ -70,7 +70,7 @@ func (m *metricsProvider) Provide(app *crd.ClowdApp, c *config.AppConfig) error return err } - if clowder_config.LoadedConfig.Features.CreateServiceMonitor { + if clowderconfig.LoadedConfig.Features.CreateServiceMonitor { if err := createServiceMonitorObjects(m.Cache, m.Env, app, c, m.Env.Name, m.Env.Status.TargetNamespace); err != nil { return err } diff --git a/controllers/cloud.redhat.com/providers/resource_cache.go b/controllers/cloud.redhat.com/providers/resource_cache.go index 8c7189ab8..4b7119eba 100644 --- a/controllers/cloud.redhat.com/providers/resource_cache.go +++ b/controllers/cloud.redhat.com/providers/resource_cache.go @@ -6,7 +6,7 @@ import ( "fmt" crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/object" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/utils" @@ -117,7 +117,7 @@ func init() { gvk, _ := utils.GetKindFromObj(scheme, &strimzi.KafkaTopic{}) protectedGVKs[gvk] = true - if !clowder_config.LoadedConfig.Features.KedaResources { + if !clowderconfig.LoadedConfig.Features.KedaResources { gvk, _ := utils.GetKindFromObj(scheme, &keda.ScaledObject{}) protectedGVKs[gvk] = true } @@ -247,7 +247,7 @@ func (o *ObjectCache) Create(resourceIdent ResourceIdent, nn types.NamespacedNam } var jsonData []byte - if clowder_config.LoadedConfig.DebugOptions.Cache.Create || clowder_config.LoadedConfig.DebugOptions.Cache.Apply { + if clowderconfig.LoadedConfig.DebugOptions.Cache.Create || clowderconfig.LoadedConfig.DebugOptions.Cache.Apply { jsonData, _ = json.MarshalIndent(object, "", " ") } @@ -258,7 +258,7 @@ func (o *ObjectCache) Create(resourceIdent ResourceIdent, nn types.NamespacedNam jsonData: string(jsonData), } - if clowder_config.LoadedConfig.DebugOptions.Cache.Create { + if clowderconfig.LoadedConfig.DebugOptions.Cache.Create { diffVal := "hidden" if object.GetObjectKind().GroupVersionKind() != secretCompare { @@ -310,7 +310,7 @@ func (o *ObjectCache) Update(resourceIdent ResourceIdent, object client.Object) o.data[resourceIdent][nn].Object = object.DeepCopyObject().(client.Object) - if clowder_config.LoadedConfig.DebugOptions.Cache.Update { + if clowderconfig.LoadedConfig.DebugOptions.Cache.Update { var jsonData []byte jsonData, _ = json.MarshalIndent(o.data[resourceIdent][nn].Object, "", " ") if object.GetObjectKind().GroupVersionKind() == secretCompare { @@ -451,7 +451,7 @@ func (o *ObjectCache) ApplyAll() error { } for n, i := range v { o.log.Info("APPLY resource ", "namespace", n.Namespace, "name", n.Name, "provider", k.GetProvider(), "purpose", k.GetPurpose(), "kind", i.Object.GetObjectKind().GroupVersionKind().Kind, "update", i.Update) - if clowder_config.LoadedConfig.DebugOptions.Cache.Apply { + if clowderconfig.LoadedConfig.DebugOptions.Cache.Apply { jsonData, _ := json.MarshalIndent(i.Object, "", " ") diff := difflib.UnifiedDiff{ A: difflib.SplitLines(string(jsonData)), diff --git a/controllers/cloud.redhat.com/providers/web/impl.go b/controllers/cloud.redhat.com/providers/web/impl.go index 891a91242..9204426fa 100644 --- a/controllers/cloud.redhat.com/providers/web/impl.go +++ b/controllers/cloud.redhat.com/providers/web/impl.go @@ -11,7 +11,7 @@ import ( "time" crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" obj "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/object" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" deployProvider "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers/deployment" @@ -197,8 +197,8 @@ func makeKeycloak(o obj.ClowdObject, objMap providers.ObjectMap, usePVC bool, no image := "quay.io/keycloak/keycloak:11.0.3" - if clowder_config.LoadedConfig.Images.Keycloak != "" { - image = clowder_config.LoadedConfig.Images.Keycloak + if clowderconfig.LoadedConfig.Images.Keycloak != "" { + image = clowderconfig.LoadedConfig.Images.Keycloak } c := core.Container{ @@ -316,8 +316,8 @@ func makeBOP(o obj.ClowdObject, objMap providers.ObjectMap, usePVC bool, nodePor image := "quay.io/cloudservices/mbop:a8be5e9" - if clowder_config.LoadedConfig.Images.MBOP != "" { - image = clowder_config.LoadedConfig.Images.MBOP + if clowderconfig.LoadedConfig.Images.MBOP != "" { + image = clowderconfig.LoadedConfig.Images.MBOP } c := core.Container{ diff --git a/controllers/cloud.redhat.com/providers/web/local.go b/controllers/cloud.redhat.com/providers/web/local.go index f36c150f4..6a70be73a 100644 --- a/controllers/cloud.redhat.com/providers/web/local.go +++ b/controllers/cloud.redhat.com/providers/web/local.go @@ -8,7 +8,7 @@ import ( crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1/common" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/config" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers" @@ -55,12 +55,12 @@ func NewLocalWebProvider(p *providers.Provider) (providers.ClowderProvider, erro nn := providers.GetNamespacedName(p.Env, "keycloak") dataInit := func() map[string]string { - username := clowder_config.LoadedConfig.Credentials.Keycloak.Username + username := clowderconfig.LoadedConfig.Credentials.Keycloak.Username if username == "" { username = utils.RandString(8) } - password := clowder_config.LoadedConfig.Credentials.Keycloak.Password + password := clowderconfig.LoadedConfig.Credentials.Keycloak.Password if password == "" { password = utils.RandString(8) } diff --git a/controllers/cloud.redhat.com/run.go b/controllers/cloud.redhat.com/run.go index 2adf8a18a..90960c26f 100644 --- a/controllers/cloud.redhat.com/run.go +++ b/controllers/cloud.redhat.com/run.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/prometheus/client_golang/prometheus" cloudredhatcomv1alpha1 "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" @@ -62,7 +62,7 @@ func init() { // Run inits the manager and controllers and then starts the manager func Run(metricsAddr string, probeAddr string, enableLeaderElection bool, config *rest.Config, signalHandler context.Context, enableWebHooks bool) { - setupLog.Info("Loaded config", "config", clowder_config.LoadedConfig) + setupLog.Info("Loaded config", "config", clowderconfig.LoadedConfig) clowderVersion.With(prometheus.Labels{"version": Version}).Inc() diff --git a/controllers/cloud.redhat.com/status.go b/controllers/cloud.redhat.com/status.go index 60e1919e0..60d235290 100644 --- a/controllers/cloud.redhat.com/status.go +++ b/controllers/cloud.redhat.com/status.go @@ -7,7 +7,7 @@ import ( "time" crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/object" strimzi "github.com/RedHatInsights/strimzi-client-go/apis/kafka.strimzi.io/v1beta2" apps "k8s.io/api/apps/v1" @@ -93,14 +93,14 @@ func kafkaConnectStatusChecker(kafkaConnect strimzi.KafkaConnect) bool { return false } -func countDeployments(ctx context.Context, client client.Client, o object.ClowdObject) (error, int32, int32) { +func countDeployments(ctx context.Context, client client.Client, o object.ClowdObject) (int32, int32, error) { var managedDeployments int32 var readyDeployments int32 deployments := apps.DeploymentList{} err := client.List(ctx, &deployments) if err != nil { - return err, 0, 0 + return 0, 0, err } // filter for resources owned by the ClowdObject and check their status @@ -116,17 +116,17 @@ func countDeployments(ctx context.Context, client client.Client, o object.ClowdO } } - return nil, managedDeployments, readyDeployments + return managedDeployments, readyDeployments, nil } -func countKafkas(ctx context.Context, client client.Client, o object.ClowdObject) (error, int32, int32) { +func countKafkas(ctx context.Context, client client.Client, o object.ClowdObject) (int32, int32, error) { var managedDeployments int32 var readyDeployments int32 kafkas := strimzi.KafkaList{} err := client.List(ctx, &kafkas) if err != nil { - return err, 0, 0 + return 0, 0, err } // filter for resources owned by the ClowdObject and check their status @@ -142,17 +142,17 @@ func countKafkas(ctx context.Context, client client.Client, o object.ClowdObject } } - return nil, managedDeployments, readyDeployments + return managedDeployments, readyDeployments, nil } -func countKafkaTopics(ctx context.Context, client client.Client, o object.ClowdObject) (error, int32, int32) { +func countKafkaTopics(ctx context.Context, client client.Client, o object.ClowdObject) (int32, int32, error) { var managedTopics int32 var readyTopics int32 kafkaTopics := strimzi.KafkaTopicList{} err := client.List(ctx, &kafkaTopics) if err != nil { - return err, 0, 0 + return 0, 0, err } // filter for resources owned by the ClowdObject and check their status @@ -168,17 +168,17 @@ func countKafkaTopics(ctx context.Context, client client.Client, o object.ClowdO } } - return nil, managedTopics, readyTopics + return managedTopics, readyTopics, nil } -func countKafkaConnects(ctx context.Context, client client.Client, o object.ClowdObject) (error, int32, int32) { +func countKafkaConnects(ctx context.Context, client client.Client, o object.ClowdObject) (int32, int32, error) { var managedDeployments int32 var readyDeployments int32 kafkaConnects := strimzi.KafkaConnectList{} err := client.List(ctx, &kafkaConnects) if err != nil { - return err, 0, 0 + return 0, 0, err } // filter for resources owned by the ClowdObject and check their status @@ -194,7 +194,7 @@ func countKafkaConnects(ctx context.Context, client client.Client, o object.Clow } } - return nil, managedDeployments, readyDeployments + return managedDeployments, readyDeployments, nil } // SetEnvResourceStatus the status on the passed ClowdObject interface. @@ -222,29 +222,29 @@ func GetEnvResourceFigures(ctx context.Context, client client.Client, o *crd.Clo deploymentStats := crd.EnvResourceStatus{} - err, managedDeployments, readyDeployments := countDeployments(ctx, client, o) + managedDeployments, readyDeployments, err := countDeployments(ctx, client, o) if err != nil { return crd.EnvResourceStatus{}, err } totalManagedDeployments += managedDeployments totalReadyDeployments += readyDeployments - if clowder_config.LoadedConfig.Features.WatchStrimziResources { - err, managedDeployments, readyDeployments = countKafkas(ctx, client, o) + if clowderconfig.LoadedConfig.Features.WatchStrimziResources { + managedDeployments, readyDeployments, err = countKafkas(ctx, client, o) if err != nil { return crd.EnvResourceStatus{}, err } totalManagedDeployments += managedDeployments totalReadyDeployments += readyDeployments - err, managedDeployments, readyDeployments = countKafkaConnects(ctx, client, o) + managedDeployments, readyDeployments, err = countKafkaConnects(ctx, client, o) if err != nil { return crd.EnvResourceStatus{}, err } totalManagedDeployments += managedDeployments totalReadyDeployments += readyDeployments - err, managedTopics, readyTopics := countKafkaTopics(ctx, client, o) + managedTopics, readyTopics, err := countKafkaTopics(ctx, client, o) if err != nil { return crd.EnvResourceStatus{}, err } @@ -292,22 +292,22 @@ func GetAppResourceFigures(ctx context.Context, client client.Client, o *crd.Clo deploymentStats := crd.AppResourceStatus{} - err, managedDeployments, readyDeployments := countDeployments(ctx, client, o) + managedDeployments, readyDeployments, err := countDeployments(ctx, client, o) if err != nil { return crd.AppResourceStatus{}, err } totalManagedDeployments += managedDeployments totalReadyDeployments += readyDeployments - if clowder_config.LoadedConfig.Features.WatchStrimziResources { - err, managedDeployments, readyDeployments = countKafkas(ctx, client, o) + if clowderconfig.LoadedConfig.Features.WatchStrimziResources { + managedDeployments, readyDeployments, err = countKafkas(ctx, client, o) if err != nil { return crd.AppResourceStatus{}, err } totalManagedDeployments += managedDeployments totalReadyDeployments += readyDeployments - err, managedDeployments, readyDeployments = countKafkaConnects(ctx, client, o) + managedDeployments, readyDeployments, err = countKafkaConnects(ctx, client, o) if err != nil { return crd.AppResourceStatus{}, err } diff --git a/main.go b/main.go index 7727a0bc6..de600fec6 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ import ( cloudredhatcomv1alpha1 "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1" controllers "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com" - "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowder_config" + "github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig" //+kubebuilder:scaffold:imports ) @@ -66,8 +66,8 @@ func main() { ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) - if clowder_config.LoadedConfig.DebugOptions.Pprof.Enable { + if clowderconfig.LoadedConfig.DebugOptions.Pprof.Enable { go http.ListenAndServe("localhost:8000", nil) } - controllers.Run(metricsAddr, probeAddr, enableLeaderElection, ctrl.GetConfigOrDie(), ctrl.SetupSignalHandler(), !clowder_config.LoadedConfig.Features.DisableWebhooks) + controllers.Run(metricsAddr, probeAddr, enableLeaderElection, ctrl.GetConfigOrDie(), ctrl.SetupSignalHandler(), !clowderconfig.LoadedConfig.Features.DisableWebhooks) }