Skip to content

Bug 1830031: Update OLM to use UID for OG Labels #1496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
24 changes: 11 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require (
github.com/onsi/gomega v1.9.0
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0
github.com/operator-framework/api v0.3.1
github.com/operator-framework/operator-registry v1.11.0
github.com/operator-framework/api v0.3.2
github.com/operator-framework/operator-registry v1.12.1
github.com/otiai10/copy v1.0.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.2.1
Expand All @@ -36,19 +36,18 @@ require (
google.golang.org/grpc v1.27.0
gopkg.in/yaml.v2 v2.2.8
helm.sh/helm/v3 v3.1.2
k8s.io/api v0.18.0
k8s.io/apiextensions-apiserver v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/apiserver v0.18.0
k8s.io/client-go v0.18.0
k8s.io/code-generator v0.18.0
k8s.io/component-base v0.18.0
k8s.io/api v0.18.2
k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery v0.18.2
k8s.io/apiserver v0.18.2
k8s.io/client-go v0.18.2
k8s.io/code-generator v0.18.2
k8s.io/component-base v0.18.2
k8s.io/klog v1.0.0
k8s.io/kube-aggregator v0.18.0
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.5.2
sigs.k8s.io/controller-tools v0.2.8
sigs.k8s.io/controller-runtime v0.6.0
sigs.k8s.io/controller-tools v0.3.0
sigs.k8s.io/kind v0.7.0
)

Expand All @@ -58,7 +57,6 @@ replace (
github.com/openshift/api => github.com/openshift/api v0.0.0-20200331152225-585af27e34fd // release-4.5
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 // release-4.5

github.com/operator-framework/api => github.com/operator-framework/api v0.3.1
github.com/prometheus/client_golang => github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
google.golang.org/grpc => google.golang.org/grpc v1.26.0 // https://github.com/etcd-io/etcd/issues/11563

Expand Down
69 changes: 49 additions & 20 deletions go.sum

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pkg/controller/install/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func (i *StrategyDeploymentInstaller) createOrUpdateWebhook(caPEM []byte, desc v
if err != nil || len(operatorGroups) != 1 {
return fmt.Errorf("Error retrieving OperatorGroup info")
}
ogNamespacelabelSelector := operatorGroups[0].NamespaceLabelSelector()
ogNamespacelabelSelector, err := operatorGroups[0].NamespaceLabelSelector()
if err != nil {
return err
}

switch desc.Type {
case v1alpha1.ValidatingAdmissionWebhook:
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ func (a *Operator) syncNamespace(obj interface{}) error {
if namespace.Labels == nil {
namespace.Labels = make(map[string]string, 1)
}
ogLabelKey, ogLabelValue := group.OGLabelKeyAndValue()
ogLabelKey, ogLabelValue, err := group.OGLabelKeyAndValue()
if err != nil {
return err
}
namespace.Labels[ogLabelKey] = ogLabelValue
}
}
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/csv_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3336,8 +3336,11 @@ var _ = Describe("CSV", func() {
actualWebhook, err := c.KubernetesInterface().AdmissionregistrationV1().ValidatingWebhookConfigurations().Get(context.TODO(), webhook.Name, metav1.GetOptions{})
require.NoError(GinkgoT(), err)

ogLabel, err := getOGLabelKey(og)
require.NoError(GinkgoT(), err)

expected := &metav1.LabelSelector{
MatchLabels: map[string]string{"olm.operatorgroup/" + namespace.Name + "." + og.GetName(): ""},
MatchLabels: map[string]string{ogLabel: ""},
MatchExpressions: []metav1.LabelSelectorRequirement(nil),
}

Expand Down
18 changes: 14 additions & 4 deletions test/e2e/operator_groups_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ var _ = Describe("Operator Group", func() {
TargetNamespaces: []string{},
},
}
_, err := crc.OperatorsV1().OperatorGroups(testNamespaceA).Create(context.TODO(), operatorGroup, metav1.CreateOptions{})
operatorGroup, err := crc.OperatorsV1().OperatorGroups(testNamespaceA).Create(context.TODO(), operatorGroup, metav1.CreateOptions{})
require.NoError(GinkgoT(), err)

// Cleanup OperatorGroup
Expand All @@ -2096,7 +2096,8 @@ var _ = Describe("Operator Group", func() {
}()

// Create the OperatorGroup Label
ogLabel := fmt.Sprintf("olm.operatorgroup/%s.%s", testNamespaceA, operatorGroup.GetName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: can we make this a method of *OperatorGroup or a wrapper?

ogLabel, err := getOGLabelKey(operatorGroup)
require.NoError(GinkgoT(), err)

// Create list options
listOptions := metav1.ListOptions{
Expand Down Expand Up @@ -2186,11 +2187,12 @@ var _ = Describe("Operator Group", func() {
TargetNamespaces: testNamespaces,
},
}
_, err := crc.OperatorsV1().OperatorGroups(testNamespaceA).Create(context.TODO(), operatorGroup, metav1.CreateOptions{})
operatorGroup, err := crc.OperatorsV1().OperatorGroups(testNamespaceA).Create(context.TODO(), operatorGroup, metav1.CreateOptions{})
require.NoError(GinkgoT(), err)

// Create the OperatorGroup Label
ogLabel := fmt.Sprintf("olm.operatorgroup/%s.%s", testNamespaceA, operatorGroup.GetName())
ogLabel, err := getOGLabelKey(operatorGroup)
require.NoError(GinkgoT(), err)

// Create list options
listOptions := metav1.ListOptions{
Expand Down Expand Up @@ -2325,3 +2327,11 @@ func containsNamespace(namespaces []corev1.Namespace, namespaceName string) bool
}
return false
}

func getOGLabelKey(og *v1.OperatorGroup) (string, error) {
ogUID := string(og.GetUID())
if ogUID == "" {
return "", fmt.Errorf("OperatorGroup UID is empty string")
}
return fmt.Sprintf("olm.operatorgroup.uid/%s", og.GetUID()), nil
}
2 changes: 1 addition & 1 deletion upstream.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY go.sum go.sum
COPY cmd cmd
COPY util util
COPY test test
RUN make build
RUN CGO_ENABLED=0 make build
RUN make build-util

FROM alpine:latest
Expand Down
68 changes: 68 additions & 0 deletions vendor/github.com/containerd/containerd/archive/strconv.go

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

Loading