Skip to content

Commit

Permalink
Fixed a few static check issues
Browse files Browse the repository at this point in the history
* Always use "providers" for provider import
* Fixed a few other suggestions
  • Loading branch information
psav committed Apr 12, 2021
1 parent 1fe4ad8 commit f6f3d01
Show file tree
Hide file tree
Showing 43 changed files with 151 additions and 207 deletions.
9 changes: 4 additions & 5 deletions controllers/cloud.redhat.com/clowdenvironment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *ClowdEnvironmentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
}
}

log.Info("Reconciliation started", "env", fmt.Sprintf("%s", env.Name))
log.Info("Reconciliation started", "env", env.Name)

if env.Status.TargetNamespace == "" {
if env.Spec.TargetNamespace != "" {
Expand Down Expand Up @@ -174,7 +174,7 @@ func (r *ClowdEnvironmentReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
}

if err == nil {
if _, ok := managedEnvironments[env.Name]; ok == false {
if _, ok := managedEnvironments[env.Name]; !ok {
managedEnvironments[env.Name] = true
}
managedEnvsMetric.Set(float64(len(managedEnvironments)))
Expand Down Expand Up @@ -345,9 +345,8 @@ func (r *ClowdEnvironmentReconciler) setAppInfo(p providers.Provider) error {

func (r *ClowdEnvironmentReconciler) finalizeEnvironment(reqLogger logr.Logger, e *crd.ClowdEnvironment) error {

if _, ok := managedEnvironments[e.Name]; ok == true {
delete(managedEnvironments, e.Name)
}
delete(managedEnvironments, e.Name)

if e.Spec.TargetNamespace == "" {
namespace := &core.Namespace{}
namespace.SetName(e.Status.TargetNamespace)
Expand Down
16 changes: 9 additions & 7 deletions controllers/cloud.redhat.com/clowdjobinvocation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ func (r *ClowdJobInvocationReconciler) Reconcile(req ctrl.Request) (ctrl.Result,
// Set the initial status to an empty list of pods and a Completed
// status of false. If a job has been invoked, but hasn't finished,
// setting the status after requeue will ensure it won't be double invoked
err = r.setCompletedStatus(ctx, &cji)
if err != nil {
if err := r.setCompletedStatus(ctx, &cji); err != nil {
return ctrl.Result{Requeue: true}, err
}

if err := r.Client.Status().Update(ctx, &cji); err != nil {
return ctrl.Result{Requeue: true}, err
}
err = r.Client.Status().Update(ctx, &cji)

// If the status is updated to complete, don't invoke again.
if cji.Status.Completed {
Expand Down Expand Up @@ -309,12 +311,12 @@ func (r *ClowdJobInvocationReconciler) cjiToEnqueueUponJobUpdate(a handler.MapOb
}

job := batchv1.Job{}
err := r.Client.Get(ctx, obj, &job)
if err := r.Client.Get(ctx, obj, &job); err != nil {
r.Log.Error(err, "Failed to fetch Job")
}

cjiList := crd.ClowdJobInvocationList{}
err = r.Client.List(ctx, &cjiList)

if err != nil {
if err := r.Client.List(ctx, &cjiList); err != nil {
if k8serr.IsNotFound(err) {
// Must have been deleted
return reqs
Expand Down
10 changes: 4 additions & 6 deletions controllers/cloud.redhat.com/providers/database/appinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/errors"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
core "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -22,7 +21,7 @@ var rdsCa string
const caURL string = "https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem"

type appInterface struct {
p.Provider
providers.Provider
Config config.DatabaseConfig
}

Expand All @@ -47,15 +46,14 @@ func fetchCa() (string, error) {
caBundle := string(body)

if !strings.HasPrefix(caBundle, "-----BEGIN CERTIFICATE") {
msg := fmt.Sprintf("Invalid RDS CA bundle")
return "", errors.New(msg)
return "", errors.New("Invalid RDS CA bundle")
}

return caBundle, nil
}

// NewAppInterfaceDBProvider creates a new app-interface DB provider obejct.
func NewAppInterfaceDBProvider(p *p.Provider) (providers.ClowderProvider, error) {
func NewAppInterfaceDBProvider(p *providers.Provider) (providers.ClowderProvider, error) {
provider := appInterface{Provider: *p}

if rdsCa == "" {
Expand Down Expand Up @@ -189,7 +187,7 @@ func genDbConfigs(secrets []core.Secret) ([]config.DatabaseConfig, error) {
}

keys := []string{"db.host", "db.port", "db.user", "db.password", "db.name"}
p.ExtractSecretData(secrets, extractFn, keys...)
providers.ExtractSecretData(secrets, extractFn, keys...)

if err != nil {
return nil, err
Expand Down
15 changes: 7 additions & 8 deletions controllers/cloud.redhat.com/providers/database/localdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ import (
provutils "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers/utils"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/utils"

p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

// LocalDBDeployment is the ident refering to the local DB deployment object.
var LocalDBDeployment = p.NewSingleResourceIdent(ProvName, "local_db_deployment", &apps.Deployment{})
var LocalDBDeployment = providers.NewSingleResourceIdent(ProvName, "local_db_deployment", &apps.Deployment{})

// LocalDBService is the ident refering to the local DB service object.
var LocalDBService = p.NewSingleResourceIdent(ProvName, "local_db_service", &core.Service{})
var LocalDBService = providers.NewSingleResourceIdent(ProvName, "local_db_service", &core.Service{})

// LocalDBPVC is the ident refering to the local DB PVC object.
var LocalDBPVC = p.NewSingleResourceIdent(ProvName, "local_db_pvc", &core.PersistentVolumeClaim{})
var LocalDBPVC = providers.NewSingleResourceIdent(ProvName, "local_db_pvc", &core.PersistentVolumeClaim{})

// LocalDBSecret is the ident refering to the local DB secret object.
var LocalDBSecret = p.NewSingleResourceIdent(ProvName, "local_db_secret", &core.Secret{})
var LocalDBSecret = providers.NewSingleResourceIdent(ProvName, "local_db_secret", &core.Secret{})

type localDbProvider struct {
p.Provider
providers.Provider
Config config.DatabaseConfig
}

// NewLocalDBProvider returns a new local DB provider object.
func NewLocalDBProvider(p *p.Provider) (providers.ClowderProvider, error) {
func NewLocalDBProvider(p *providers.Provider) (providers.ClowderProvider, error) {
return &localDbProvider{Provider: *p}, nil
}

Expand Down Expand Up @@ -74,7 +73,7 @@ func (db *localDbProvider) Provide(app *crd.ClowdApp, c *config.AppConfig) error
}
}

secMap, err := p.MakeOrGetSecret(db.Ctx, app, db.Cache, LocalDBSecret, nn, dataInit)
secMap, err := providers.MakeOrGetSecret(db.Ctx, app, db.Cache, LocalDBSecret, nn, dataInit)
if err != nil {
return errors.Wrap("Couldn't set/get secret", err)
}
Expand Down
5 changes: 2 additions & 3 deletions controllers/cloud.redhat.com/providers/database/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

type noneDbProvider struct {
p.Provider
providers.Provider
Config config.DatabaseConfig
}

// NewNoneDBProvider returns a new none db provider object.
func NewNoneDBProvider(p *p.Provider) (providers.ClowderProvider, error) {
func NewNoneDBProvider(p *providers.Provider) (providers.ClowderProvider, error) {
return &noneDbProvider{Provider: *p}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package dependencies
import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

type dependenciesProvider struct {
p.Provider
providers.Provider
}

// NewDependenciesProvider returns a new End provider run at the end of the provider set.
func NewDependenciesProvider(p *p.Provider) (p.ClowderProvider, error) {
func NewDependenciesProvider(p *providers.Provider) (providers.ClowderProvider, error) {
return &dependenciesProvider{Provider: *p}, nil
}

Expand Down
32 changes: 0 additions & 32 deletions controllers/cloud.redhat.com/providers/dependencies/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"

"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -324,33 +322,3 @@ func NewIDAndParam(ID, limitCPU, limitMemory, requestsCPU, requestsMemory string
},
}
}

func createResourceRequirements(params Params) core.ResourceRequirements {
rl := core.ResourceList{}
limits := params["limits"]

if limits != nil {
if limits["cpu"] != "" {
rl["cpu"] = resource.MustParse(limits["cpu"])
}
if limits["memory"] != "" {
rl["memory"] = resource.MustParse(limits["memory"])
}
}

rr := core.ResourceList{}
requests := params["requests"]
if requests != nil {
if requests["cpu"] != "" {
rr["cpu"] = resource.MustParse(requests["cpu"])
}
if requests["memory"] != "" {
rr["memory"] = resource.MustParse(requests["memory"])
}
}

return core.ResourceRequirements{
Limits: rl,
Requests: rr,
}
}
6 changes: 3 additions & 3 deletions controllers/cloud.redhat.com/providers/deployment/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package deployment
import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

type deploymentProvider struct {
p.Provider
providers.Provider
}

func NewDeploymentProvider(p *p.Provider) (p.ClowderProvider, error) {
func NewDeploymentProvider(p *providers.Provider) (providers.ClowderProvider, error) {
return &deploymentProvider{Provider: *p}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/cloud.redhat.com/providers/deployment/provider.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package deployment

import (
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
apps "k8s.io/api/apps/v1"
)

// ProvName sets the provider name identifier
var ProvName = "deployment"

// CoreDeployment is the deployment for the apps deployments.
var CoreDeployment = p.NewMultiResourceIdent(ProvName, "core_deployment", &apps.Deployment{})
var CoreDeployment = providers.NewMultiResourceIdent(ProvName, "core_deployment", &apps.Deployment{})

// GetEnd returns the correct end provider.
func GetDeployment(c *p.Provider) (p.ClowderProvider, error) {
func GetDeployment(c *providers.Provider) (providers.ClowderProvider, error) {
return NewDeploymentProvider(c)
}

func init() {
p.ProvidersRegistration.Register(GetDeployment, 0, ProvName)
providers.ProvidersRegistration.Register(GetDeployment, 0, ProvName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

type appInterfaceFeatureFlagProvider struct {
p.Provider
providers.Provider
}

// NewAppInterfaceFeatureFlagsProvider creates a new app-interface feature flags provider.
func NewAppInterfaceFeatureFlagsProvider(p *p.Provider) (providers.ClowderProvider, error) {
func NewAppInterfaceFeatureFlagsProvider(p *providers.Provider) (providers.ClowderProvider, error) {
return &appInterfaceFeatureFlagProvider{Provider: *p}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,27 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"

p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

// LocalFFDBDeployment is the ident refering to the local Feature Flags DB deployment object.
var LocalFFDBDeployment = p.NewSingleResourceIdent(ProvName, "ff_db_deployment", &apps.Deployment{})
var LocalFFDBDeployment = providers.NewSingleResourceIdent(ProvName, "ff_db_deployment", &apps.Deployment{})

// LocalFFDBService is the ident refering to the local Feature Flags DB service object.
var LocalFFDBService = p.NewSingleResourceIdent(ProvName, "ff_db_service", &core.Service{})
var LocalFFDBService = providers.NewSingleResourceIdent(ProvName, "ff_db_service", &core.Service{})

// LocalFFDBPVC is the ident refering to the local Feature Flags DB PVC object.
var LocalFFDBPVC = p.NewSingleResourceIdent(ProvName, "ff_db_pvc", &core.PersistentVolumeClaim{})
var LocalFFDBPVC = providers.NewSingleResourceIdent(ProvName, "ff_db_pvc", &core.PersistentVolumeClaim{})

// LocalFFDBSecret is the ident refering to the local Feature Flags DB secret object.
var LocalFFDBSecret = p.NewSingleResourceIdent(ProvName, "ff_db_secret", &core.Secret{})
var LocalFFDBSecret = providers.NewSingleResourceIdent(ProvName, "ff_db_secret", &core.Secret{})

type localFeatureFlagsProvider struct {
p.Provider
providers.Provider
Config config.FeatureFlagsConfig
}

// NewLocalFeatureFlagsProvider returns a new local featureflags provider object.
func NewLocalFeatureFlagsProvider(p *p.Provider) (providers.ClowderProvider, error) {
func NewLocalFeatureFlagsProvider(p *providers.Provider) (providers.ClowderProvider, error) {

ffp := &localFeatureFlagsProvider{Provider: *p, Config: config.FeatureFlagsConfig{}}

Expand Down
5 changes: 2 additions & 3 deletions controllers/cloud.redhat.com/providers/featureflags/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

type noneFeatureFlagProvider struct {
p.Provider
providers.Provider
}

// NewNoneFeatureFlagsProvider returns a new none feature flags provider object.
func NewNoneFeatureFlagsProvider(p *p.Provider) (providers.ClowderProvider, error) {
func NewNoneFeatureFlagsProvider(p *providers.Provider) (providers.ClowderProvider, error) {
return &noneFeatureFlagProvider{Provider: *p}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/errors"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
core "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type elasticache struct {
p.Provider
providers.Provider
Config config.InMemoryDBConfig
}

Expand Down Expand Up @@ -48,7 +47,7 @@ func (e *elasticache) Provide(app *crd.ClowdApp, config *config.AppConfig) error
}
}

if found == false {
if !found {
return &errors.MissingDependencies{
MissingDeps: map[string][]string{
"in-memory-db-secret": {app.Name},
Expand Down
5 changes: 2 additions & 3 deletions controllers/cloud.redhat.com/providers/inmemorydb/none.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
crd "cloud.redhat.com/clowder/v2/apis/cloud.redhat.com/v1alpha1"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/config"
"cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
p "cloud.redhat.com/clowder/v2/controllers/cloud.redhat.com/providers"
)

type noneInMemoryDbProvider struct {
p.Provider
providers.Provider
}

// NewNoneInMemoryDb returns a new none in-memory DB provider object.
func NewNoneInMemoryDb(p *p.Provider) (providers.ClowderProvider, error) {
func NewNoneInMemoryDb(p *providers.Provider) (providers.ClowderProvider, error) {
return &noneInMemoryDbProvider{Provider: *p}, nil
}

Expand Down
Loading

0 comments on commit f6f3d01

Please sign in to comment.