Skip to content

Commit

Permalink
💥 removed code from pr #70 (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdumpp committed Dec 5, 2023
1 parent 0cdbe39 commit 481d857
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 57 deletions.
59 changes: 2 additions & 57 deletions internal/controller/styra/system_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,18 +827,6 @@ func (r *SystemReconciler) reconcileOPAToken(

update := false

// backwards compatibility: StyraSystem
if isControlledByStyraSystem(&s) {
log.Info("Secret owned by StyraSystem. Taking ownership.")
s.OwnerReferences = nil
if err := controllerutil.SetControllerReference(system, &s, r.Scheme); err != nil {
return ctrl.Result{}, false, ctrlerr.Wrap(err, "Could not set owner reference on Secret").
WithEvent("ErrorOwnerRefOPATokenSecret").
WithSystemCondition(v1beta1.ConditionTypeOPATokenUpdated)
}
update = true
}

if !metav1.IsControlledBy(&s, system) {
return ctrl.Result{}, false, ctrlerr.New("Existing secret is not owned by controller. Skipping update").
WithEvent("ErrorSecretNotOwnedByController").
Expand All @@ -865,16 +853,6 @@ func (r *SystemReconciler) reconcileOPAToken(
return ctrl.Result{}, update, nil
}

// backwards compatibility: StyraSystem
func isControlledByStyraSystem(o metav1.Object) bool {
for _, ref := range o.GetOwnerReferences() {
if ref.Kind == "StyraSystem" {
return true
}
}
return false
}

func (r *SystemReconciler) reconcileOPAConfigMap(
ctx context.Context,
log logr.Logger,
Expand Down Expand Up @@ -933,18 +911,6 @@ func (r *SystemReconciler) reconcileOPAConfigMap(

update := false

// backwards compatibility: StyraSystem
if isControlledByStyraSystem(&cm) {
log.Info("ConfigMap owned by StyraSystem. Taking ownership.")
cm.OwnerReferences = nil
if err := controllerutil.SetControllerReference(system, &cm, r.Scheme); err != nil {
return ctrl.Result{}, false, ctrlerr.Wrap(err, "Could not set owner reference on Secret").
WithEvent("ErrorOwnerRefOPATokenSecret").
WithSystemCondition(v1beta1.ConditionTypeOPATokenUpdated)
}
update = true
}

if !metav1.IsControlledBy(&cm, system) {
return ctrl.Result{}, false, ctrlerr.New("ConfigMap already exists and is not owned by controller").
WithEvent("ErrorConfigMapNotOwnedByController").
Expand Down Expand Up @@ -1025,18 +991,6 @@ func (r *SystemReconciler) reconcileSLPConfigMap(

update := false

// backwards compatibility: StyraSystem
if isControlledByStyraSystem(&cm) {
log.Info("ConfigMap owned by StyraSystem. Taking ownership.")
cm.OwnerReferences = nil
if err := controllerutil.SetControllerReference(system, &cm, r.Scheme); err != nil {
return ctrl.Result{}, false, ctrlerr.Wrap(err, "Could not set owner reference on Secret").
WithEvent("ErrorOwnerRefOPATokenSecret").
WithSystemCondition(v1beta1.ConditionTypeOPATokenUpdated)
}
update = true
}

if !metav1.IsControlledBy(&cm, system) {
return ctrl.Result{}, false, ctrlerr.New("ConfigMap already exists and is not owned by controller").
WithEvent("ErrorFetchSLPConfigMap").
Expand Down Expand Up @@ -1294,17 +1248,8 @@ func (r *SystemReconciler) findSecretOwners(ctx context.Context, secret client.O
}

func ownerIsSystem(owner metav1.OwnerReference) bool {
if owner.APIVersion != v1beta1.GroupVersion.String() &&
// backwards compatibility: StyraSystem
owner.APIVersion != "styra.bankdata.dk/v1alpha1" {
return false
}
if owner.Kind != "System" &&
// backwards compatibility: StyraSystem
owner.Kind != "StyraSystem" {
return false
}
return true
return owner.APIVersion == v1beta1.GroupVersion.String() &&
owner.Kind == "System"
}

// findSystemsForConfigMap detects if modified configmap is the configmap containing opa/slp config.
Expand Down
8 changes: 8 additions & 0 deletions internal/webhook/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions pkg/styra/mocks/client_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 481d857

Please sign in to comment.