Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed May 7, 2024
1 parent f5f580a commit 4fd0820
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
30 changes: 19 additions & 11 deletions controllers/core/flagd/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,25 @@ func (r *ResourceReconciler) Reconcile(ctx context.Context, flagd *api.Flagd, ob
}

if exists && !resource.AreObjectsEqual(existingObj, newObj) {
r.Log.Info(fmt.Sprintf("Updating %v", newObj))
if err := r.Client.Update(ctx, newObj); err != nil {
r.Log.Error(err, fmt.Sprintf("Failed to update Flagd %s '%s/%s'", obj.GetObjectKind(), flagd.Namespace, flagd.Name))
return err
}
} else {
r.Log.Info(fmt.Sprintf("Creating %v", newObj))
if err := r.Client.Create(ctx, newObj); err != nil {
r.Log.Error(err, fmt.Sprintf("Failed to create Flagd %s '%s/%s'", obj.GetObjectKind(), flagd.Namespace, flagd.Name))
return err
}
return r.updateResource(ctx, flagd, obj, newObj)
}
return r.createResource(ctx, flagd, obj, newObj)
}

func (r *ResourceReconciler) createResource(ctx context.Context, flagd *api.Flagd, obj client.Object, newObj client.Object) error {
r.Log.Info(fmt.Sprintf("Creating %v", newObj))
if err := r.Client.Create(ctx, newObj); err != nil {
r.Log.Error(err, fmt.Sprintf("Failed to create Flagd %s '%s/%s'", obj.GetObjectKind(), flagd.Namespace, flagd.Name))
return err
}
return nil
}

func (r *ResourceReconciler) updateResource(ctx context.Context, flagd *api.Flagd, obj client.Object, newObj client.Object) error {
r.Log.Info(fmt.Sprintf("Updating %v", newObj))
if err := r.Client.Update(ctx, newObj); err != nil {
r.Log.Error(err, fmt.Sprintf("Failed to update Flagd %s '%s/%s'", obj.GetObjectKind(), flagd.Namespace, flagd.Name))
return err
}
return nil
}
4 changes: 2 additions & 2 deletions controllers/core/flagd/resources/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func (r *FlagdDeployment) GetResource(ctx context.Context, flagd *api.Flagd) (cl
Namespace: flagd.Spec.FeatureFlagSourceRef.Namespace,
Name: flagd.Spec.FeatureFlagSourceRef.Name,
}, featureFlagSource); err != nil {
return nil, fmt.Errorf("could not look up feature flag source for flagd: %v", err)
return nil, fmt.Errorf("could not look up feature flag source for flagd: %w", err)
}

err := r.FlagdInjector.InjectFlagd(ctx, &deployment.ObjectMeta, &deployment.Spec.Template.Spec, &featureFlagSource.Spec)
if err != nil {
return nil, fmt.Errorf("could not inject flagd container into deployment: %v", err)
return nil, fmt.Errorf("could not inject flagd container into deployment: %w", err)
}

if len(deployment.Spec.Template.Spec.Containers) == 0 {
Expand Down
1 change: 1 addition & 0 deletions controllers/core/flagd/resources/deployment_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:dupl
package resources

import (
Expand Down
1 change: 1 addition & 0 deletions controllers/core/flagd/resources/ingress_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:dupl
package resources

import (
Expand Down
1 change: 1 addition & 0 deletions controllers/core/flagd/resources/service_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint:dupl
package resources

import (
Expand Down

0 comments on commit 4fd0820

Please sign in to comment.