Skip to content

Commit

Permalink
Update dependencies (#76)
Browse files Browse the repository at this point in the history
* Update dependencies

* Prevent second cleanup attempt on image repository deletion
  • Loading branch information
mmorhun authored Nov 14, 2023
1 parent de983aa commit 7afe656
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 270 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Build the manager binary
# For more details and updates, refer to
# https://catalog.redhat.com/software/containers/ubi9/go-toolset/61e5c00b4ec9945c18787690
FROM registry.access.redhat.com/ubi9/go-toolset:1.19.13-4.1697647145 as builder
FROM registry.access.redhat.com/ubi9/go-toolset:1.20.10 as builder

# Copy the Go Modules manifests
COPY go.mod go.mod
Expand Down
2 changes: 0 additions & 2 deletions config/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ health:
healthProbeBindAddress: :8081
metrics:
bindAddress: 127.0.0.1:8080
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: ed4c18c3.appstudio.redhat.com
Expand Down
71 changes: 43 additions & 28 deletions controllers/component_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, err
}
log.Info("Image repository finalizer removed from the Component", l.Action, l.ActionDelete)

r.waitComponentUpdateInCache(ctx, req.NamespacedName, func(component *appstudioredhatcomv1alpha1.Component) bool {
return !controllerutil.ContainsFinalizer(component, ImageRepositoryComponentFinalizer)
})
}

return ctrl.Result{}, nil
Expand Down Expand Up @@ -298,34 +302,10 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
log.Info("Component updated successfully", l.Action, l.ActionUpdate)

// Here we do some trick.
// The problem is that the component update triggers both: a new reconcile and operator cache update.
// In other words we are getting race condition. If a new reconcile is triggered before cache update,
// requested build action will be repeated, because the last update has not yet visible for the operator.
// For example, instead of one initial pipeline run we could get two.
// To resolve the problem above, instead of just ending the reconcile loop here,
// we are waiting for the cache update. This approach prevents next reconciles with outdated cache.
isComponentInCacheUpToDate := false
for i := 0; i < 5; i++ {
if err = r.Client.Get(ctx, req.NamespacedName, component); err == nil {
if _, exists := component.Annotations[GenerateImageAnnotationName]; !exists {
isComponentInCacheUpToDate = true
break
}
// Outdated version of the component, wait more.
} else {
if errors.IsNotFound(err) {
// The component was deleted
isComponentInCacheUpToDate = true
break
}
log.Error(err, "failed to get the component for annotation update check", l.Action, l.ActionView)
}
time.Sleep(100 * time.Millisecond)
}
if !isComponentInCacheUpToDate {
log.Info("failed to wait for updated cache. Requested action could be repeated.", l.Audit, "true")
}
r.waitComponentUpdateInCache(ctx, req.NamespacedName, func(component *appstudioredhatcomv1alpha1.Component) bool {
_, exists := component.Annotations[GenerateImageAnnotationName]
return !exists
})
}

return ctrl.Result{}, nil
Expand All @@ -342,6 +322,41 @@ func (r *ComponentReconciler) reportError(ctx context.Context, component *appstu
return r.Client.Update(ctx, component)
}

// waitComponentUpdateInCache waits for operator cache update with newer version of the component.
// Here we do some trick.
// The problem is that the component update triggers both: a new reconcile and operator cache update.
// In other words we are getting race condition. If a new reconcile is triggered before cache update,
// requested build action will be repeated, because the last update has not yet visible for the operator.
// For example, instead of one initial pipeline run we could get two.
// To resolve the problem above, instead of just ending the reconcile loop here,
// we are waiting for the cache update. This approach prevents next reconciles with outdated cache.
func (r *ComponentReconciler) waitComponentUpdateInCache(ctx context.Context, componentKey types.NamespacedName, componentUpdated func(component *appstudioredhatcomv1alpha1.Component) bool) {
log := ctrllog.FromContext(ctx).WithName("waitComponentUpdateInCache")

component := &appstudioredhatcomv1alpha1.Component{}
isComponentInCacheUpToDate := false
for i := 0; i < 10; i++ {
if err := r.Client.Get(ctx, componentKey, component); err == nil {
if componentUpdated(component) {
isComponentInCacheUpToDate = true
break
}
// Outdated version of the component, wait more.
} else {
if errors.IsNotFound(err) {
// The component was deleted
isComponentInCacheUpToDate = true
break
}
log.Error(err, "failed to get the component for annotation update check", l.Action, l.ActionView)
}
time.Sleep(100 * time.Millisecond)
}
if !isComponentInCacheUpToDate {
log.Info("failed to wait for updated cache. Requested action could be repeated.", l.Audit, "true")
}
}

// ensureRobotAccountSecret creates or updates robot account secret.
// Returns secret string data.
func (r *ComponentReconciler) ensureRobotAccountSecret(ctx context.Context, component *appstudioredhatcomv1alpha1.Component, robotAccount *quay.RobotAccount, secretName, imageURL string) (map[string]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ var _ = BeforeSuite(func() {

By("bootstrapping test environment")

applicationApiDepVersion := "v0.0.0-20221220162402-c1e887791dac"
remoteSecretApiDepVersion := "v0.0.0-20230711070755-b39d2b5f892e"
applicationApiDepVersion := "v0.0.0-20231026192857-89515ad2504f"
remoteSecretApiDepVersion := "v0.0.0-20231108162916-8f7ff94e0e6a"

testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{
Expand Down
96 changes: 48 additions & 48 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
module github.com/redhat-appstudio/image-controller

go 1.19
go 1.20

require (
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/h2non/gock v1.2.0
github.com/onsi/ginkgo/v2 v2.9.2
github.com/onsi/gomega v1.27.6
github.com/redhat-appstudio/application-api v0.0.0-20221220162402-c1e887791dac
github.com/redhat-appstudio/remote-secret v0.0.0-20230711070755-b39d2b5f892e
go.uber.org/zap v1.24.0
gotest.tools/v3 v3.0.3
k8s.io/api v0.26.1
k8s.io/apimachinery v0.27.3
k8s.io/client-go v0.26.1
k8s.io/klog/v2 v2.90.1
sigs.k8s.io/controller-runtime v0.14.6
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/redhat-appstudio/application-api v0.0.0-20231026192857-89515ad2504f
github.com/redhat-appstudio/remote-secret v0.0.0-20231108162916-8f7ff94e0e6a
go.uber.org/zap v1.26.0
gotest.tools/v3 v3.5.0
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/client-go v0.28.3
k8s.io/klog/v2 v2.110.1
sigs.k8s.io/controller-runtime v0.16.3
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
golang.org/x/tools v0.15.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/component-base v0.26.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 7afe656

Please sign in to comment.