Skip to content

OCPBUGS-7102: make plugin e2e tests skippable #444

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 3 commits into from
Feb 15, 2023
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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ e2e/operator-registry: ## Run e2e registry tests
e2e/olm: ## Run e2e olm tests
$(MAKE) e2e WHAT=operator-lifecycle-manager E2E_CATALOG_NS=openshift-marketplace E2E_INSTALL_NS=openshift-operator-lifecycle-manager E2E_TEST_NS=openshift-operators E2E_TIMEOUT=120m KUBECTL=oc

.PHONY: update-plugin-deps
update-plugin-deps:
./scripts/update_plugin_deps.sh

.PHONY: vendor
vendor:
vendor: update-plugin-deps
go mod tidy
go mod vendor
go mod verify
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a // indirect
github.com/openshift/cluster-policy-controller v0.0.0-20220825134653-523e4104074f // indirect
github.com/openshift/cluster-policy-controller v0.0.0-20230112143856-3f8efde27bb6 // indirect
github.com/otiai10/copy v1.2.0 // indirect
github.com/pbnjay/strptime v0.0.0-20140226051138-5c05b0d668c9 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,8 @@ github.com/openshift/api v0.0.0-20210517065120-b325f58df679/go.mod h1:dZ4kytOo3s
github.com/openshift/build-machinery-go v0.0.0-20210209125900-0da259a2c359/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0 h1:kMiuiZXH1GdfbiMwsuAQOqGaMxlo9NCUk0wT4XAdfNM=
github.com/openshift/client-go v0.0.0-20200326155132-2a6cd50aedd0/go.mod h1:uUQ4LClRO+fg5MF/P6QxjMCb1C9f7Oh4RKepftDnEJE=
github.com/openshift/cluster-policy-controller v0.0.0-20220825134653-523e4104074f h1:ll0eE7rgGHsFlrI6ksr6nXL2ur8GYBe8Jj0GwNQ/1+o=
github.com/openshift/cluster-policy-controller v0.0.0-20220825134653-523e4104074f/go.mod h1:r9ZZT5wjwoS2heBfYR26uJhhkGYwgmFqomu9ww0y9Qw=
github.com/openshift/cluster-policy-controller v0.0.0-20230112143856-3f8efde27bb6 h1:JJ8cHS+mXYwaYjpDnmnEWNj/KPvlVhed1dFLsz3zJ3g=
github.com/openshift/cluster-policy-controller v0.0.0-20230112143856-3f8efde27bb6/go.mod h1:mxj0Tg1YG9PpVJDOBLsAkjZNVvQTNu1LJkw9fSAkOE4=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
Expand Down
16 changes: 16 additions & 0 deletions scripts/update_plugin_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# This script is used to keep certain dependencies regularly updated
# against the same OCP branch of the current build.

BRANCH=$(git rev-parse --abbrev-ref HEAD)

echo "updating olm plugin dependencies"
if [[ "$BRANCH" =~ ^master$|^release-\d+\.\d+$ ]]; then
echo "attempting to update cluster-policy-controller"
# needed for staging/operator-lifecycle-manager/pkg/controller/operators/olm/plugins/downstream_csv_namespace_labeler_plugin.go
go get "github.com/openshift/cluster-policy-controller@${BRANCH}"
else
echo "skipping dependency update as branch '$BRANCH' is not recognized"
fi
echo "finished updating olm plugin dependencies"
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"fmt"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/plugins"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const CsvLabelerPluginId plugins.PluginID = "csv-labeler-plugin"
const labelSyncerLabelKey = ""

func NewCSVLabelSyncerLabeler(client operatorclient.ClientInterface, logger *logrus.Logger) *CSVLabelSyncerLabeler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import (
)

func init() {
operatorPlugInFactoryFuncs = []plugins.OperatorPlugInFactoryFunc{
operatorPlugInFactoryFuncs = plugins.OperatorPlugInFactoryMap{
// labels unlabeled non-payload openshift-* csv namespaces with
// security.openshift.io/scc.podSecurityLabelSync: true
plugins.NewCsvNamespaceLabelerPluginFunc,
CsvLabelerPluginId: plugins.NewCsvNamespaceLabelerPluginFunc,
}
}

func IsPluginEnabled(pluginID plugins.PluginID) bool {
_, ok := operatorPlugInFactoryFuncs[pluginID]
return ok
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (

// this unexported operator plugin slice provides an entrypoint for
// downstream to inject its own plugins to augment the controller behavior
var operatorPlugInFactoryFuncs []plugins.OperatorPlugInFactoryFunc
var operatorPlugInFactoryFuncs plugins.OperatorPlugInFactoryMap

type Operator struct {
queueinformer.Operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package plugins
import (
"context"
"errors"
"os/exec"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -298,21 +296,3 @@ func Test_SyncDoesNotLabelNamespacesWithCopiedCSVs(t *testing.T) {
assert.NoError(t, err)
assert.NotContains(t, ns.GetLabels(), NamespaceLabelSyncerLabelKey)
}

func Test_OCPVersion(t *testing.T) {
// This test is a maintenance alert that means the next OCP version is now in active development.
// This plugin relies on a list of payload namespaces that comes from the cluster-policy-controller project
// https://github.com/openshift/cluster-policy-controller/tree/master/pkg/psalabelsyncer
// This list is dependent on the OCP version. Please update the dependency version to correspond to the one
// vendored for the new OCP version (or contact the responsible team if it hasn't been updated yet).
// Then, bump the OCP version in the `nextOCPUncutBranchName` constant below
const nextOCPUncutBranchName = "release-4.14"
const errorMessage = "[maintenance alert] new ocp version branch has been cut: please check comments in test for instructions"

// Get branches
branches, err := exec.Command("git", "branch", "-a").Output()
assert.NoError(t, err)

// check if the next uncut branch has been cut and fail if so
assert.False(t, strings.Contains(string(branches), nextOCPUncutBranchName), errorMessage)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/sirupsen/logrus"
)

type PluginID string
type OperatorPlugInFactoryMap map[PluginID]OperatorPlugInFactoryFunc

// HostOperator is an extensible and observable operator that hosts the plug-in, i.e. which the plug-in is extending
type HostOperator interface {
queueinformer.ObservableOperator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/plugins"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/util"
Expand All @@ -31,6 +32,10 @@ var _ = Describe("CSV Namespace Labeler Plugin", func() {
})

It("should not label non openshift- namespaces", func() {
if !olm.IsPluginEnabled(olm.CsvLabelerPluginId) {
Skip("csv labeler plugin is disabled")
}

// create namespace with operator group
testNamespace = SetupGeneratedTestNamespace(genName("csv-ns-labeler-"))

Expand All @@ -46,6 +51,10 @@ var _ = Describe("CSV Namespace Labeler Plugin", func() {
})

It("should label a non-payload openshift- namespace", func() {
if !olm.IsPluginEnabled(olm.CsvLabelerPluginId) {
Skip("csv labeler plugin is disabled")
}

// create namespace with operator group
testNamespace = SetupGeneratedTestNamespace(genName("openshift-csv-ns-labeler-"))

Expand All @@ -61,6 +70,10 @@ var _ = Describe("CSV Namespace Labeler Plugin", func() {
})

It("should relabel a non-payload openshift- namespace containing csvs if the label is deleted", func() {
if !olm.IsPluginEnabled(olm.CsvLabelerPluginId) {
Skip("csv labeler plugin is disabled")
}

// create namespace with operator group
testNamespace = SetupGeneratedTestNamespace(genName("openshift-csv-ns-labeler-"))

Expand Down

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

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

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

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

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ github.com/openshift/client-go/config/informers/externalversions/config
github.com/openshift/client-go/config/informers/externalversions/config/v1
github.com/openshift/client-go/config/informers/externalversions/internalinterfaces
github.com/openshift/client-go/config/listers/config/v1
# github.com/openshift/cluster-policy-controller v0.0.0-20220825134653-523e4104074f
## explicit; go 1.18
# github.com/openshift/cluster-policy-controller v0.0.0-20230112143856-3f8efde27bb6
## explicit; go 1.19
github.com/openshift/cluster-policy-controller/pkg/psalabelsyncer/nsexemptions
# github.com/operator-framework/api v0.17.3 => ./staging/api
## explicit; go 1.18
Expand Down