diff --git a/cmd/olm/cleanup.go b/cmd/olm/cleanup.go new file mode 100644 index 0000000000..a414ade139 --- /dev/null +++ b/cmd/olm/cleanup.go @@ -0,0 +1,117 @@ +package main + +import ( + "time" + + "github.com/sirupsen/logrus" + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + + "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned" + "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" +) + +const ( + pollInterval = 1 * time.Second + pollDuration = 5 * time.Minute +) + +type checkResourceFunc func() error +type deleteResourceFunc func() error + +func cleanup(logger *logrus.Logger, c operatorclient.ClientInterface, crc versioned.Interface) { + if err := waitForDelete(checkCatalogSource(crc, "olm-operators"), deleteCatalogSource(crc, "olm-operators")); err != nil { + logger.WithError(err).Fatal("couldn't clean previous release") + } + + if err := waitForDelete(checkConfigMap(c, "olm-operators"), deleteConfigMap(c, "olm-operators")); err != nil { + logger.WithError(err).Fatal("couldn't clean previous release") + } + + if err := waitForDelete(checkSubscription(crc, "packageserver"), deleteSubscription(crc, "packageserver")); err != nil { + logger.WithError(err).Fatal("couldn't clean previous release") + } + + if err := waitForDelete(checkClusterServiceVersion(crc, "packageserver.v0.10.0"), deleteClusterServiceVersion(crc, "packageserver.v0.10.0")); err != nil { + logger.WithError(err).Fatal("couldn't clean previous release") + } + + if err := waitForDelete(checkClusterServiceVersion(crc, "packageserver.v0.9.0"), deleteClusterServiceVersion(crc, "packageserver.v0.9.0")); err != nil { + logger.WithError(err).Fatal("couldn't clean previous release") + } +} + +func waitForDelete(checkResource checkResourceFunc, deleteResource deleteResourceFunc) error { + if err := checkResource(); err != nil && errors.IsNotFound(err) { + return nil + } + if err := deleteResource(); err != nil { + return err + } + var err error + err = wait.Poll(pollInterval, pollDuration, func() (bool, error) { + err := checkResource() + if errors.IsNotFound(err) { + return true, nil + } + if err != nil { + return false, err + } + return false, nil + }) + + return err +} + +func checkClusterServiceVersion(crc versioned.Interface, name string) checkResourceFunc { + return func() error { + _, err := crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Get(name, metav1.GetOptions{}) + return err + } +} + +func deleteClusterServiceVersion(crc versioned.Interface, name string) deleteResourceFunc { + return func() error { + return crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Delete(name, metav1.NewDeleteOptions(0)) + } +} + +func checkSubscription(crc versioned.Interface, name string) checkResourceFunc { + return func() error { + _, err := crc.OperatorsV1alpha1().Subscriptions(*namespace).Get(name, metav1.GetOptions{}) + return err + } +} + +func deleteSubscription(crc versioned.Interface, name string) deleteResourceFunc { + return func() error { + return crc.OperatorsV1alpha1().Subscriptions(*namespace).Delete(name, metav1.NewDeleteOptions(0)) + } +} + +func checkConfigMap(c operatorclient.ClientInterface, name string) checkResourceFunc { + return func() error { + _, err := c.KubernetesInterface().CoreV1().ConfigMaps(*namespace).Get(name, metav1.GetOptions{}) + return err + } +} + +func deleteConfigMap(c operatorclient.ClientInterface, name string) deleteResourceFunc { + return func() error { + return c.KubernetesInterface().CoreV1().ConfigMaps(*namespace).Delete(name, metav1.NewDeleteOptions(0)) + } +} + +func checkCatalogSource(crc versioned.Interface, name string) checkResourceFunc { + return func() error { + _, err := crc.OperatorsV1alpha1().CatalogSources(*namespace).Get(name, metav1.GetOptions{}) + return err + } +} + +func deleteCatalogSource(crc versioned.Interface, name string) deleteResourceFunc { + return func() error { + return crc.OperatorsV1alpha1().CatalogSources(*namespace).Delete(name, metav1.NewDeleteOptions(0)) + } +} diff --git a/cmd/olm/main.go b/cmd/olm/main.go index 04c44ff128..54676edc8e 100644 --- a/cmd/olm/main.go +++ b/cmd/olm/main.go @@ -63,6 +63,9 @@ var ( profiling = flag.Bool( "profiling", false, "serve profiling data (on port 8080)") + + namespace = flag.String( + "namespace", "", "namespace where cleanup runs") ) func init() { @@ -165,6 +168,8 @@ func main() { log.Fatalf("error configuring client: %s", err.Error()) } + cleanup(logger, opClient, crClient) + // Create a new instance of the operator. op, err := olm.NewOperator( ctx, @@ -176,7 +181,8 @@ func main() { olm.WithRestConfig(config), ) if err != nil { - log.Fatalf("error configuring operator: %s", err.Error()) + log.WithError(err).Fatalf("error configuring operator") + return } op.Run(ctx) diff --git a/deploy/chart/templates/0000_50_olm_07-olm-operator.deployment.yaml b/deploy/chart/templates/0000_50_olm_07-olm-operator.deployment.yaml index e66980658b..b3e1363c81 100644 --- a/deploy/chart/templates/0000_50_olm_07-olm-operator.deployment.yaml +++ b/deploy/chart/templates/0000_50_olm_07-olm-operator.deployment.yaml @@ -26,6 +26,8 @@ spec: command: - /bin/olm args: + - -namespace + - ${OPERATOR_NAMESPACE} {{- if .Values.watchedNamespaces }} - -watchedNamespaces - {{ .Values.watchedNamespaces }} diff --git a/deploy/chart/templates/0000_50_olm_11-olm-operators.configmap.yaml b/deploy/chart/templates/0000_50_olm_11-olm-operators.configmap.yaml deleted file mode 100644 index b1e32d3017..0000000000 --- a/deploy/chart/templates/0000_50_olm_11-olm-operators.configmap.yaml +++ /dev/null @@ -1,11 +0,0 @@ -kind: ConfigMap -apiVersion: v1 -metadata: - name: olm-operators - namespace: {{ .Values.namespace }} -data: - customResourceDefinitions: |- - clusterServiceVersions: |- -{{- include "packageserver.clusterserviceversion" . | cat "-" | nindent 6 | replace " - apiVersion" " - apiVersion" }} - packages: |- -{{- include "packageserver.package" . | nindent 4 }} diff --git a/deploy/chart/templates/0000_50_olm_12-olm-operators.catalogsource.yaml b/deploy/chart/templates/0000_50_olm_12-olm-operators.catalogsource.yaml deleted file mode 100644 index 8edde8c92e..0000000000 --- a/deploy/chart/templates/0000_50_olm_12-olm-operators.catalogsource.yaml +++ /dev/null @@ -1,12 +0,0 @@ -#! validate-crd: ./deploy/chart/templates/06-catalogsource.crd.yaml -#! parse-kind: CatalogSource -apiVersion: operators.coreos.com/v1alpha1 -kind: CatalogSource -metadata: - name: olm-operators - namespace: {{ .Values.namespace }} -spec: - sourceType: internal - configMap: olm-operators - displayName: OLM Operators - publisher: Red Hat diff --git a/deploy/chart/templates/0000_50_olm_14-packageserver.subscription.yaml b/deploy/chart/templates/0000_50_olm_14-packageserver.subscription.yaml deleted file mode 100644 index ec62b3f07d..0000000000 --- a/deploy/chart/templates/0000_50_olm_14-packageserver.subscription.yaml +++ /dev/null @@ -1,12 +0,0 @@ -#! validate-crd: ./deploy/chart/templates/05-subscription.crd.yaml -#! parse-kind: Subscription -apiVersion: operators.coreos.com/v1alpha1 -kind: Subscription -metadata: - name: packageserver - namespace: {{ .Values.namespace }} -spec: - source: olm-operators - sourceNamespace: {{ .Values.namespace }} - name: packageserver - channel: alpha diff --git a/deploy/chart/templates/0000_50_olm_15-packageserver.clusterserviceversion.yaml b/deploy/chart/templates/0000_50_olm_15-packageserver.clusterserviceversion.yaml index a066433bbe..7c95f56920 100644 --- a/deploy/chart/templates/0000_50_olm_15-packageserver.clusterserviceversion.yaml +++ b/deploy/chart/templates/0000_50_olm_15-packageserver.clusterserviceversion.yaml @@ -1,3 +1 @@ -{{ if and .Values.installType (eq .Values.installType "ocp") }} {{- include "packageserver.clusterserviceversion" . }} -{{- end }} diff --git a/deploy/chart/templates/0000_50_olm_16-packageserver.deployment.yaml b/deploy/chart/templates/0000_50_olm_16-packageserver.deployment.yaml deleted file mode 100644 index b44647134f..0000000000 --- a/deploy/chart/templates/0000_50_olm_16-packageserver.deployment.yaml +++ /dev/null @@ -1,10 +0,0 @@ -{{- if and .Values.installType (eq .Values.installType "ocp") -}} -apiVersion: apps/v1 -kind: Deployment -metadata: - name: packageserver - namespace: {{ .Values.namespace }} - labels: - app: packageserver -{{- include "packageserver.deployment-spec" . | nindent 0 }} -{{- end }} diff --git a/deploy/chart/templates/0000_50_olm_18-service-monitor.yaml b/deploy/chart/templates/0000_90_olm_00-service-monitor.yaml similarity index 100% rename from deploy/chart/templates/0000_50_olm_18-service-monitor.yaml rename to deploy/chart/templates/0000_90_olm_00-service-monitor.yaml diff --git a/deploy/chart/templates/_packageserver.clusterserviceversion.yaml b/deploy/chart/templates/_packageserver.clusterserviceversion.yaml index ecf60fd87a..5739dff461 100644 --- a/deploy/chart/templates/_packageserver.clusterserviceversion.yaml +++ b/deploy/chart/templates/_packageserver.clusterserviceversion.yaml @@ -2,9 +2,10 @@ apiVersion: operators.coreos.com/v1alpha1 kind: ClusterServiceVersion metadata: - name: packageserver.v{{ .Chart.Version }} + name: packageserver namespace: {{ .Values.namespace }} labels: + olm.version: {{ .Chart.Version }} {{- if .Values.writePackageServerStatusName }} olm.clusteroperator.name: {{ .Values.writePackageServerStatusName }} {{- end }} @@ -34,7 +35,7 @@ spec: strategy: deployment spec: clusterPermissions: - - serviceAccountName: packageserver + - serviceAccountName: olm-operator-serviceaccount rules: - apiGroups: - authorization.k8s.io diff --git a/deploy/chart/templates/_packageserver.deployment-spec.yaml b/deploy/chart/templates/_packageserver.deployment-spec.yaml index 8bad567f0e..392a5cb05e 100644 --- a/deploy/chart/templates/_packageserver.deployment-spec.yaml +++ b/deploy/chart/templates/_packageserver.deployment-spec.yaml @@ -11,7 +11,7 @@ spec: labels: app: packageserver spec: - serviceAccountName: packageserver + serviceAccountName: olm-operator-serviceaccount {{- if and .Values.installType (eq .Values.installType "ocp") }} priorityClassName: "system-cluster-critical" {{- end }} diff --git a/manifests/0000_50_olm_07-olm-operator.deployment.yaml b/manifests/0000_50_olm_07-olm-operator.deployment.yaml index 9e72fc0d9d..f42d13fbcb 100644 --- a/manifests/0000_50_olm_07-olm-operator.deployment.yaml +++ b/manifests/0000_50_olm_07-olm-operator.deployment.yaml @@ -24,6 +24,8 @@ spec: command: - /bin/olm args: + - -namespace + - ${OPERATOR_NAMESPACE} - -writeStatusName - operator-lifecycle-manager - -writePackageServerStatusName diff --git a/manifests/0000_50_olm_11-olm-operators.configmap.yaml b/manifests/0000_50_olm_11-olm-operators.configmap.yaml deleted file mode 100644 index bb551892bb..0000000000 --- a/manifests/0000_50_olm_11-olm-operators.configmap.yaml +++ /dev/null @@ -1,269 +0,0 @@ -kind: ConfigMap -apiVersion: v1 -metadata: - name: olm-operators - namespace: openshift-operator-lifecycle-manager -data: - customResourceDefinitions: |- - clusterServiceVersions: |- - - apiVersion: operators.coreos.com/v1alpha1 - kind: ClusterServiceVersion - metadata: - name: packageserver.v0.9.0 - namespace: openshift-operator-lifecycle-manager - spec: - displayName: Package Server - description: Represents an Operator package that is available from a given CatalogSource which will resolve to a ClusterServiceVersion. - minKubeVersion: 1.11.0 - keywords: ['packagemanifests', 'olm', 'packages'] - maintainers: - - name: Red Hat - email: openshift-operators@redhat.com - provider: - name: Red Hat - links: - - name: Package Server - url: https://github.com/operator-framework/operator-lifecycle-manager/tree/master/pkg/package-server - installModes: - - type: OwnNamespace - supported: true - - type: SingleNamespace - supported: true - - type: MultiNamespace - supported: true - - type: AllNamespaces - supported: true - install: - strategy: deployment - spec: - clusterPermissions: - - serviceAccountName: packageserver - rules: - - apiGroups: - - authorization.k8s.io - resources: - - subjectaccessreviews - verbs: - - create - - get - - apiGroups: - - "" - resources: - - configmaps - verbs: - - get - - list - - watch - - apiGroups: - - "operators.coreos.com" - resources: - - catalogsources - verbs: - - get - - list - - watch - - apiGroups: - - "packages.operators.coreos.com" - resources: - - packagemanifests - verbs: - - get - - list - deployments: - - name: packageserver - spec: - strategy: - type: RollingUpdate - replicas: 2 - selector: - matchLabels: - app: packageserver - template: - metadata: - labels: - app: packageserver - spec: - serviceAccountName: packageserver - nodeSelector: - beta.kubernetes.io/os: linux - node-role.kubernetes.io/master: "" - - tolerations: - - operator: Exists - - containers: - - name: packageserver - command: - - /bin/package-server - - -v=4 - - --secure-port - - "5443" - - --global-namespace - - openshift-operator-lifecycle-manager - image: quay.io/operator-framework/olm@sha256:7e4b13b89b3d59876b228697bbd0c9e364fd73f946ab90308c34fd82053a5a76 - imagePullPolicy: IfNotPresent - priorityClassName: "system-cluster-critical" - ports: - - containerPort: 5443 - livenessProbe: - httpGet: - scheme: HTTPS - path: /healthz - port: 5443 - readinessProbe: - httpGet: - scheme: HTTPS - path: /healthz - port: 5443 - maturity: alpha - version: 0.9.0 - apiservicedefinitions: - owned: - - group: packages.operators.coreos.com - version: v1 - kind: PackageManifest - name: packagemanifests - displayName: PackageManifest - description: A PackageManifest is a resource generated from existing CatalogSources and their ConfigMaps - deploymentName: packageserver - containerPort: 5443 - - apiVersion: operators.coreos.com/v1alpha1 - kind: ClusterServiceVersion - metadata: - name: packageserver.v0.10.1 - namespace: openshift-operator-lifecycle-manager - labels: - olm.clusteroperator.name: operator-lifecycle-manager-packageserver - spec: - displayName: Package Server - description: Represents an Operator package that is available from a given CatalogSource which will resolve to a ClusterServiceVersion. - minKubeVersion: 1.11.0 - replaces: packageserver.v0.9.0 - keywords: ['packagemanifests', 'olm', 'packages'] - maintainers: - - name: Red Hat - email: openshift-operators@redhat.com - provider: - name: Red Hat - links: - - name: Package Server - url: https://github.com/operator-framework/operator-lifecycle-manager/tree/master/pkg/package-server - installModes: - - type: OwnNamespace - supported: true - - type: SingleNamespace - supported: true - - type: MultiNamespace - supported: true - - type: AllNamespaces - supported: true - install: - strategy: deployment - spec: - clusterPermissions: - - serviceAccountName: packageserver - rules: - - apiGroups: - - authorization.k8s.io - resources: - - subjectaccessreviews - verbs: - - create - - get - - apiGroups: - - "" - resources: - - configmaps - verbs: - - get - - list - - watch - - apiGroups: - - "operators.coreos.com" - resources: - - catalogsources - verbs: - - get - - list - - watch - - apiGroups: - - "packages.operators.coreos.com" - resources: - - packagemanifests - verbs: - - get - - list - deployments: - - name: packageserver - spec: - strategy: - type: RollingUpdate - replicas: 2 - selector: - matchLabels: - app: packageserver - template: - metadata: - labels: - app: packageserver - spec: - serviceAccountName: packageserver - priorityClassName: "system-cluster-critical" - nodeSelector: - beta.kubernetes.io/os: linux - node-role.kubernetes.io/master: "" - - tolerations: - - effect: NoSchedule - key: node-role.kubernetes.io/master - operator: Exists - - effect: NoExecute - key: node.kubernetes.io/unreachable - operator: Exists - tolerationSeconds: 120 - - effect: NoExecute - key: node.kubernetes.io/not-ready - operator: Exists - tolerationSeconds: 120 - - containers: - - name: packageserver - command: - - /bin/package-server - - -v=4 - - --secure-port - - "5443" - - --global-namespace - - openshift-marketplace - image: quay.io/operator-framework/olm@sha256:f965474776bada158e4bf7be5c84b54460843e7478f06060990d2fdeb31b0b90 - imagePullPolicy: IfNotPresent - ports: - - containerPort: 5443 - livenessProbe: - httpGet: - scheme: HTTPS - path: /healthz - port: 5443 - readinessProbe: - httpGet: - scheme: HTTPS - path: /healthz - port: 5443 - terminationMessagePolicy: FallbackToLogsOnError - maturity: alpha - version: 0.10.1 - apiservicedefinitions: - owned: - - group: packages.operators.coreos.com - version: v1 - kind: PackageManifest - name: packagemanifests - displayName: PackageManifest - description: A PackageManifest is a resource generated from existing CatalogSources and their ConfigMaps - deploymentName: packageserver - containerPort: 5443 - packages: |- - - packageName: packageserver - channels: - - name: alpha - currentCSV: packageserver.v0.10.1 diff --git a/manifests/0000_50_olm_12-olm-operators.catalogsource.yaml b/manifests/0000_50_olm_12-olm-operators.catalogsource.yaml deleted file mode 100644 index 361818ada7..0000000000 --- a/manifests/0000_50_olm_12-olm-operators.catalogsource.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: operators.coreos.com/v1alpha1 -kind: CatalogSource -metadata: - name: olm-operators - namespace: openshift-operator-lifecycle-manager -spec: - sourceType: internal - configMap: olm-operators - displayName: OLM Operators - publisher: Red Hat diff --git a/manifests/0000_50_olm_14-packageserver.subscription.yaml b/manifests/0000_50_olm_14-packageserver.subscription.yaml deleted file mode 100644 index a995fa4060..0000000000 --- a/manifests/0000_50_olm_14-packageserver.subscription.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: operators.coreos.com/v1alpha1 -kind: Subscription -metadata: - name: packageserver - namespace: openshift-operator-lifecycle-manager -spec: - source: olm-operators - sourceNamespace: openshift-operator-lifecycle-manager - name: packageserver - channel: alpha diff --git a/manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml b/manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml index b3f847de5d..53b993f2f4 100644 --- a/manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml +++ b/manifests/0000_50_olm_15-packageserver.clusterserviceversion.yaml @@ -1,15 +1,15 @@ apiVersion: operators.coreos.com/v1alpha1 kind: ClusterServiceVersion metadata: - name: packageserver.v0.10.1 + name: packageserver namespace: openshift-operator-lifecycle-manager labels: + olm.version: 0.10.1 olm.clusteroperator.name: operator-lifecycle-manager-packageserver spec: displayName: Package Server description: Represents an Operator package that is available from a given CatalogSource which will resolve to a ClusterServiceVersion. minKubeVersion: 1.11.0 - replaces: packageserver.v0.9.0 keywords: ['packagemanifests', 'olm', 'packages'] maintainers: - name: Red Hat @@ -32,7 +32,7 @@ spec: strategy: deployment spec: clusterPermissions: - - serviceAccountName: packageserver + - serviceAccountName: olm-operator-serviceaccount rules: - apiGroups: - authorization.k8s.io @@ -78,7 +78,7 @@ spec: labels: app: packageserver spec: - serviceAccountName: packageserver + serviceAccountName: olm-operator-serviceaccount priorityClassName: "system-cluster-critical" nodeSelector: beta.kubernetes.io/os: linux diff --git a/manifests/0000_50_olm_16-packageserver.deployment.yaml b/manifests/0000_50_olm_16-packageserver.deployment.yaml deleted file mode 100644 index 3156420fa5..0000000000 --- a/manifests/0000_50_olm_16-packageserver.deployment.yaml +++ /dev/null @@ -1,62 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: packageserver - namespace: openshift-operator-lifecycle-manager - labels: - app: packageserver -spec: - strategy: - type: RollingUpdate - replicas: 2 - selector: - matchLabels: - app: packageserver - template: - metadata: - labels: - app: packageserver - spec: - serviceAccountName: packageserver - priorityClassName: "system-cluster-critical" - nodeSelector: - beta.kubernetes.io/os: linux - node-role.kubernetes.io/master: "" - - tolerations: - - effect: NoSchedule - key: node-role.kubernetes.io/master - operator: Exists - - effect: NoExecute - key: node.kubernetes.io/unreachable - operator: Exists - tolerationSeconds: 120 - - effect: NoExecute - key: node.kubernetes.io/not-ready - operator: Exists - tolerationSeconds: 120 - - containers: - - name: packageserver - command: - - /bin/package-server - - -v=4 - - --secure-port - - "5443" - - --global-namespace - - openshift-marketplace - image: quay.io/operator-framework/olm@sha256:f965474776bada158e4bf7be5c84b54460843e7478f06060990d2fdeb31b0b90 - imagePullPolicy: IfNotPresent - ports: - - containerPort: 5443 - livenessProbe: - httpGet: - scheme: HTTPS - path: /healthz - port: 5443 - readinessProbe: - httpGet: - scheme: HTTPS - path: /healthz - port: 5443 - terminationMessagePolicy: FallbackToLogsOnError diff --git a/pkg/controller/operators/catalog/operator_test.go b/pkg/controller/operators/catalog/operator_test.go index e38c0369c7..a4f8cd60df 100644 --- a/pkg/controller/operators/catalog/operator_test.go +++ b/pkg/controller/operators/catalog/operator_test.go @@ -241,11 +241,11 @@ func TestExecutePlan(t *testing.T) { Resource: v1alpha1.StepResource{ CatalogSource: "catalog", CatalogSourceNamespace: namespace, - Group: "", - Version: "v1", - Kind: "Service", - Name: "service", - Manifest: toManifest(service("service", namespace)), + Group: "", + Version: "v1", + Kind: "Service", + Name: "service", + Manifest: toManifest(service("service", namespace)), }, Status: v1alpha1.StepStatusUnknown, }, @@ -253,11 +253,11 @@ func TestExecutePlan(t *testing.T) { Resource: v1alpha1.StepResource{ CatalogSource: "catalog", CatalogSourceNamespace: namespace, - Group: "operators.coreos.com", - Version: "v1alpha1", - Kind: "ClusterServiceVersion", - Name: "csv", - Manifest: toManifest(csv("csv", namespace, nil, nil)), + Group: "operators.coreos.com", + Version: "v1alpha1", + Kind: "ClusterServiceVersion", + Name: "csv", + Manifest: toManifest(csv("csv", namespace, nil, nil)), }, Status: v1alpha1.StepStatusUnknown, }, diff --git a/pkg/controller/operators/olm/operator.go b/pkg/controller/operators/olm/operator.go index 9e46da226d..5ffc4ef150 100644 --- a/pkg/controller/operators/olm/operator.go +++ b/pkg/controller/operators/olm/operator.go @@ -7,9 +7,9 @@ import ( "strings" "time" - log "github.com/sirupsen/logrus" v1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1" "github.com/sirupsen/logrus" + log "github.com/sirupsen/logrus" corev1 "k8s.io/api/core/v1" extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -51,8 +51,6 @@ var ( ErrAPIServiceOwnerConflict = errors.New("unable to adopt APIService") ) -var timeNow = func() metav1.Time { return metav1.NewTime(time.Now().UTC()) } - type Operator struct { queueinformer.Operator @@ -152,8 +150,12 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(csvQueueInformer) - csvInformer.Informer().AddIndexers(cache.Indexers{index.MetaLabelIndexFuncKey: index.MetaLabelIndexFunc}) + if err := op.RegisterQueueInformer(csvQueueInformer); err != nil { + return nil, err + } + if err := csvInformer.Informer().AddIndexers(cache.Indexers{index.MetaLabelIndexFuncKey: index.MetaLabelIndexFunc}); err != nil { + return nil, err + } csvIndexer := csvInformer.Informer().GetIndexer() op.csvIndexers[namespace] = csvIndexer @@ -170,7 +172,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(csvCopyQueueInformer) + if err := op.RegisterQueueInformer(csvCopyQueueInformer); err != nil { + return nil, err + } // Register separate queue for gcing csvs csvGCQueue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), fmt.Sprintf("%s/csv-gc", namespace)) @@ -185,7 +189,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(csvGCQueueInformer) + if err := op.RegisterQueueInformer(csvGCQueueInformer); err != nil { + return nil, err + } // Wire OperatorGroup reconciliation operatorGroupInformer := extInformerFactory.Operators().V1().OperatorGroups() @@ -202,7 +208,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(operatorGroupQueueInformer) + if err := op.RegisterQueueInformer(operatorGroupQueueInformer); err != nil { + return nil, err + } // Wire Deployments k8sInformerFactory := informers.NewSharedInformerFactoryWithOptions(op.opClient.KubernetesInterface(), config.resyncPeriod, informers.WithNamespace(namespace)) @@ -217,7 +225,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(depQueueInformer) + if err := op.RegisterQueueInformer(depQueueInformer); err != nil { + return nil, err + } // Set up RBAC informers roleInformer := k8sInformerFactory.Rbac().V1().Roles() @@ -231,7 +241,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(roleQueueInformer) + if err := op.RegisterQueueInformer(roleQueueInformer); err != nil { + return nil, err + } roleBindingInformer := k8sInformerFactory.Rbac().V1().RoleBindings() op.lister.RbacV1().RegisterRoleBindingLister(namespace, roleBindingInformer.Lister()) @@ -244,7 +256,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(roleBindingQueueInformer) + if err := op.RegisterQueueInformer(roleBindingQueueInformer); err != nil { + return nil, err + } // Register Secret QueueInformer secretInformer := k8sInformerFactory.Core().V1().Secrets() @@ -258,7 +272,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(secretQueueInformer) + if err := op.RegisterQueueInformer(secretQueueInformer); err != nil { + return nil, err + } // Register Service QueueInformer serviceInformer := k8sInformerFactory.Core().V1().Services() @@ -272,7 +288,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(serviceQueueInformer) + if err := op.RegisterQueueInformer(serviceQueueInformer); err != nil { + return nil, err + } // Register ServiceAccount QueueInformer serviceAccountInformer := k8sInformerFactory.Core().V1().ServiceAccounts() @@ -283,7 +301,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat queueinformer.WithInformer(serviceAccountInformer.Informer()), queueinformer.WithSyncer(k8sSyncer), ) - op.RegisterQueueInformer(serviceAccountQueueInformer) + if err := op.RegisterQueueInformer(serviceAccountQueueInformer); err != nil { + return nil, err + } } k8sInformerFactory := informers.NewSharedInformerFactory(op.opClient.KubernetesInterface(), config.resyncPeriod) @@ -298,7 +318,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(clusterRoleQueueInformer) + if err := op.RegisterQueueInformer(clusterRoleQueueInformer); err != nil { + return nil, err + } clusterRoleBindingInformer := k8sInformerFactory.Rbac().V1().ClusterRoleBindings() op.lister.RbacV1().RegisterClusterRoleBindingLister(clusterRoleBindingInformer.Lister()) @@ -311,7 +333,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(clusterRoleBindingQueueInformer) + if err := op.RegisterQueueInformer(clusterRoleBindingQueueInformer); err != nil { + return nil, err + } // register namespace queueinformer namespaceInformer := k8sInformerFactory.Core().V1().Namespaces() @@ -331,7 +355,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(namespaceQueueInformer) + if err := op.RegisterQueueInformer(namespaceQueueInformer); err != nil { + return nil, err + } // Register APIService QueueInformer apiServiceInformer := kagg.NewSharedInformerFactory(op.opClient.ApiregistrationV1Interface(), config.resyncPeriod).Apiregistration().V1().APIServices() @@ -346,7 +372,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(apiServiceQueueInformer) + if err := op.RegisterQueueInformer(apiServiceQueueInformer); err != nil { + return nil, err + } // Register CustomResourceDefinition QueueInformer crdInformer := extinf.NewSharedInformerFactory(op.opClient.ApiextensionsV1beta1Interface(), config.resyncPeriod).Apiextensions().V1beta1().CustomResourceDefinitions() @@ -360,7 +388,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat if err != nil { return nil, err } - op.RegisterQueueInformer(crdQueueInformer) + if err := op.RegisterQueueInformer(crdQueueInformer); err != nil { + return nil, err + } return op, nil } @@ -1426,7 +1456,7 @@ func (a *Operator) apiServiceOwnerConflicts(csv *v1alpha1.ClusterServiceVersion) continue } - adoptable, err := a.isAPIServiceAdoptable(csv, apiService) + adoptable, err := a.isAPIServiceAdoptable(csv, apiService) if err != nil { a.logger.WithFields(log.Fields{"obj": "apiService", "labels": apiService.GetLabels()}).Errorf("adoption check failed - %v", err) } diff --git a/scripts/install_local.sh b/scripts/install_local.sh index 013494fc04..ec2fd7a25d 100755 --- a/scripts/install_local.sh +++ b/scripts/install_local.sh @@ -31,7 +31,7 @@ kubectl rollout status -w deployment/catalog-operator --namespace="${namespace}" retries=50 until [[ $retries == 0 || $new_csv_phase == "Succeeded" ]]; do - new_csv_phase=$(kubectl get csv -n "${namespace}" packageserver.v1.0.0 -o jsonpath='{.status.phase}' 2>/dev/null || echo "Waiting for CSV to appear") + new_csv_phase=$(kubectl get csv -n "${namespace}" packageserver -o jsonpath='{.status.phase}' 2>/dev/null || echo "Waiting for CSV to appear") if [[ $new_csv_phase != "$csv_phase" ]]; then csv_phase=$new_csv_phase echo "Package server phase: $csv_phase" @@ -41,7 +41,7 @@ until [[ $retries == 0 || $new_csv_phase == "Succeeded" ]]; do done if [ $retries == 0 ]; then - echo "CSV \"packageserver.v1.0.0\" failed to reach phase succeeded" + echo "CSV \"packageserver\" failed to reach phase succeeded" exit 1 fi diff --git a/test/e2e/catalog_e2e_test.go b/test/e2e/catalog_e2e_test.go index 3bc028ec23..7703739690 100644 --- a/test/e2e/catalog_e2e_test.go +++ b/test/e2e/catalog_e2e_test.go @@ -13,7 +13,6 @@ import ( "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/selection" "k8s.io/apimachinery/pkg/util/wait" "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" @@ -80,26 +79,6 @@ func TestCatalogLoadingBetweenRestarts(t *testing.T) { t.Logf("Catalog source sucessfully loaded after rescale") } -func TestDefaultCatalogLoading(t *testing.T) { - defer cleaner.NotifyTestComplete(t, true) - c := newKubeClient(t) - crc := newCRClient(t) - - catalogSource, err := fetchCatalogSource(t, crc, "olm-operators", operatorNamespace, catalogSourceRegistryPodSynced) - require.NoError(t, err) - requirement, err := labels.NewRequirement("olm.catalogSource", selection.Equals, []string{catalogSource.GetName()}) - require.NoError(t, err) - selector := labels.NewSelector().Add(*requirement).String() - pods, err := c.KubernetesInterface().CoreV1().Pods(operatorNamespace).List(metav1.ListOptions{LabelSelector: selector}) - require.NoError(t, err) - for _, p := range pods.Items { - for _, s := range p.Status.ContainerStatuses { - require.True(t, s.Ready) - require.Zero(t, s.RestartCount) - } - } -} - func TestConfigMapUpdateTriggersRegistryPodRollout(t *testing.T) { defer cleaner.NotifyTestComplete(t, true)