Skip to content

Commit

Permalink
Fixed a number of standards issues
Browse files Browse the repository at this point in the history
  • Loading branch information
psav committed Nov 29, 2021
1 parent b703fbc commit 373d5f2
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 180 deletions.
2 changes: 1 addition & 1 deletion apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions controllers/cloud.redhat.com/clowdapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloud.redhat.com/clowdenvironment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clowder_config
package clowderconfig

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clowder_config
package clowderconfig

import (
"encoding/json"
Expand Down
225 changes: 112 additions & 113 deletions controllers/cloud.redhat.com/clowdjobinvocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloud.redhat.com/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions controllers/cloud.redhat.com/pod_mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions controllers/cloud.redhat.com/providers/autoscaler/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloud.redhat.com/providers/cronjob/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloud.redhat.com/providers/database/shareddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 373d5f2

Please sign in to comment.