Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions internal/controller/openlibertyapplication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ReconcileOpenLiberty struct {
oputils.ReconcilerBase
Log logr.Logger
watchNamespaces []string
isClusterWide bool
}

const applicationFinalizer = "finalizer.openlibertyapplications.apps.openliberty.io"
Expand Down Expand Up @@ -992,33 +993,33 @@ func (r *ReconcileOpenLiberty) SetupWithManager(mgr ctrl.Manager) error {
for _, ns := range watchNamespaces {
watchNamespacesMap[ns] = true
}
isClusterWide := oputils.IsClusterWide(watchNamespaces)
r.isClusterWide = oputils.IsClusterWide(watchNamespaces)

pred := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
// Ignore updates to CR status in which case metadata.Generation does not change
return e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() && (isClusterWide || watchNamespacesMap[e.ObjectNew.GetNamespace()])
return e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration() && (r.isClusterWide || watchNamespacesMap[e.ObjectNew.GetNamespace()])
},
CreateFunc: func(e event.CreateEvent) bool {
return isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
return r.isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
},
DeleteFunc: func(e event.DeleteEvent) bool {
return isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
return r.isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
},
GenericFunc: func(e event.GenericEvent) bool {
return isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
return r.isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
},
}

predSubResource := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
return (isClusterWide || watchNamespacesMap[e.ObjectOld.GetNamespace()])
return (r.isClusterWide || watchNamespacesMap[e.ObjectOld.GetNamespace()])
},
CreateFunc: func(e event.CreateEvent) bool {
return false
},
DeleteFunc: func(e event.DeleteEvent) bool {
return isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
return r.isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
},
GenericFunc: func(e event.GenericEvent) bool {
return false
Expand All @@ -1028,13 +1029,13 @@ func (r *ReconcileOpenLiberty) SetupWithManager(mgr ctrl.Manager) error {
predSubResWithGenCheck := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
// Ignore updates to CR status in which case metadata.Generation does not change
return (isClusterWide || watchNamespacesMap[e.ObjectOld.GetNamespace()]) && e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration()
return (r.isClusterWide || watchNamespacesMap[e.ObjectOld.GetNamespace()]) && e.ObjectOld.GetGeneration() != e.ObjectNew.GetGeneration()
},
CreateFunc: func(e event.CreateEvent) bool {
return false
},
DeleteFunc: func(e event.DeleteEvent) bool {
return isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
return r.isClusterWide || watchNamespacesMap[e.Object.GetNamespace()]
},
GenericFunc: func(e event.GenericEvent) bool {
return false
Expand Down Expand Up @@ -1139,6 +1140,8 @@ func (r *ReconcileOpenLiberty) deletePVC(reqLogger logr.Logger, pvcName string,

func (r *ReconcileOpenLiberty) getContainerImageMetadata(reqLogger logr.Logger, olapp *openlibertyv1.OpenLibertyApplication, imageRef imagev1.DockerImageReference) (string, *runtime.RawExtension, error) {
olappSecrets := []corev1.Secret{}

// check the CR-configured pull secrets
var pullSecret *corev1.Secret
if olapp.GetPullSecret() != nil {
pullSecretNames := oputils.DecodeStringToList(*olapp.GetPullSecret())
Expand All @@ -1158,6 +1161,21 @@ func (r *ReconcileOpenLiberty) getContainerImageMetadata(reqLogger logr.Logger,
}
}
}

// check the OpenShift global pull secret for inclusion
if r.isClusterWide && r.IsOpenShift() {
globalPullSecretName := "pull-secret"
globalPullSecretNamespace := "openshift-config"
globalPullSecret := &corev1.Secret{}
globalPullSecret.Name = globalPullSecretName
globalPullSecret.Namespace = globalPullSecretNamespace
err := r.GetClient().Get(context.TODO(), types.NamespacedName{Name: globalPullSecretName, Namespace: globalPullSecretNamespace}, globalPullSecret)
if err == nil {
olappSecrets = append(olappSecrets, *globalPullSecret)
} else if !kerrors.IsNotFound(err) {
return "", nil, fmt.Errorf("Failed to get the OpenShift global pull secret: %v", err)
}
}
return libertyimage.NewNamespaceCredentialsContext(reqLogger, olappSecrets, olapp.GetNamespace()).GetContainerImageMetadata(context.TODO(), imageRef, pullSecret, false)
}

Expand Down