Skip to content

Commit 33dccf1

Browse files
committed
fix(installplan): crs are ownerreferenced to their resolving csv
1 parent 7697393 commit 33dccf1

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,23 +1726,39 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
17261726
Resource: r.Name,
17271727
}
17281728

1729-
// Set up the dynamic client ResourceInterface
1729+
if step.Resolving != "" {
1730+
owner := &v1alpha1.ClusterServiceVersion{}
1731+
owner.SetNamespace(plan.GetNamespace())
1732+
owner.SetName(step.Resolving)
1733+
1734+
if r.Namespaced {
1735+
// Set OwnerReferences for namespace-scoped resource
1736+
ownerutil.AddNonBlockingOwner(unstructuredObject, owner)
1737+
1738+
// Update UIDs on all CSV OwnerReferences
1739+
updated, err := o.getUpdatedOwnerReferences(unstructuredObject.GetOwnerReferences(), plan.Namespace)
1740+
if err != nil {
1741+
return errorwrap.Wrapf(err, "error generating ownerrefs for unstructured object: %s", unstructuredObject.GetName())
1742+
}
1743+
1744+
unstructuredObject.SetOwnerReferences(updated)
1745+
} else {
1746+
// Add owner labels to cluster-scoped resource
1747+
if err := ownerutil.AddOwnerLabels(unstructuredObject, owner); err != nil {
1748+
return err
1749+
}
1750+
}
1751+
}
1752+
1753+
// Set up the dynamic client ResourceInterface and set ownerrefs
17301754
var resourceInterface dynamic.ResourceInterface
17311755
if r.Namespaced {
1732-
ownerutil.AddOwner(unstructuredObject, plan, false, false)
17331756
unstructuredObject.SetNamespace(namespace)
17341757
resourceInterface = o.dynamicClient.Resource(gvr).Namespace(namespace)
17351758
} else {
17361759
resourceInterface = o.dynamicClient.Resource(gvr)
17371760
}
17381761

1739-
// Update UIDs on all CSV OwnerReferences
1740-
updated, err := o.getUpdatedOwnerReferences(unstructuredObject.GetOwnerReferences(), plan.Namespace)
1741-
if err != nil {
1742-
return errorwrap.Wrapf(err, "error generating ownerrefs for unstructured object: %s", unstructuredObject.GetName())
1743-
}
1744-
unstructuredObject.SetOwnerReferences(updated)
1745-
17461762
// Ensure Unstructured Object
17471763
status, err := ensurer.EnsureUnstructuredObject(resourceInterface, unstructuredObject)
17481764
if err != nil {

pkg/controller/operators/catalog/operator_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,6 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
10931093
k8sClientFake.Resources = apiResourcesForObjects(append(config.extObjs, config.regObjs...))
10941094
opClientFake := operatorclient.NewClient(k8sClientFake, apiextensionsfake.NewSimpleClientset(config.extObjs...), apiregistrationfake.NewSimpleClientset(config.regObjs...))
10951095
dynamicClientFake := fakedynamic.NewSimpleDynamicClient(runtime.NewScheme())
1096-
// dynamicClientFake.Resources = k8sClientFake.Resources
10971096

10981097
// Create operator namespace
10991098
_, err := opClientFake.KubernetesInterface().CoreV1().Namespaces().Create(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}})

pkg/controller/operators/catalog/testdata/prometheusrule.cr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ apiVersion: monitoring.coreos.com/v1
22
kind: PrometheusRule
33
metadata:
44
name: rule
5-
# namespace: placeholder
65
labels:
76
prometheus: alert-rules
87
role: alert-rules

0 commit comments

Comments
 (0)