Skip to content
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

Switch api definitions to operator-framework/api #1464

Merged
merged 4 commits into from Apr 20, 2020
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM openshift/origin-release:golang-1.12 as builder
FROM openshift/origin-release:golang-1.13 as builder
RUN yum update -y
RUN yum install -y make git

Expand Down
33 changes: 20 additions & 13 deletions Makefile
Expand Up @@ -9,7 +9,10 @@ undefine GOFLAGS
endif

SHELL := /bin/bash
PKG := github.com/operator-framework/operator-lifecycle-manager
ORG := github.com/operator-framework
PKG := $(ORG)/operator-lifecycle-manager
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
MOD_FLAGS := $(shell (go version | grep -q -E "1\.1[1-9]") && echo -mod=vendor)
CMDS := $(shell go list $(MOD_FLAGS) ./cmd/...)
TCMDS := $(shell go list $(MOD_FLAGS) ./test/e2e/...)
Expand Down Expand Up @@ -39,8 +42,16 @@ all: test build

test: clean cover.out

unit:
go test $(MOD_FLAGS) $(SPECIFIC_UNIT_TEST) -v -race -count=1 ./pkg/...
unit: kubebuilder
$(KUBEBUILDER_ENV) go test $(MOD_FLAGS) $(SPECIFIC_UNIT_TEST) -v -race -count=1 ./pkg/...

# Install kubebuilder if not found
KUBEBUILDER_DIR := /tmp/kubebuilder_2.3.1_$(OS)_$(ARCH)/bin
kubebuilder:
ifeq (, $(shell which kubebuilder))
[ ! -d "$(KUBEBUILDER_DIR)" ] && (curl -sL https://go.kubebuilder.io/dl/2.3.1/$(OS)/$(ARCH) | tar -xz -C /tmp/)
KUBEBUILDER_ENV := KUBEBUILDER_ASSETS=$(KUBEBUILDER_DIR)
endif

schema-check:

Expand Down Expand Up @@ -117,7 +128,7 @@ setup-bare: clean e2e.namespace

# e2e test exculding the rh-operators directory which tests rh-operators and their metric cardinality.
e2e:
go test -v $(MOD_FLAGS) -failfast -timeout 70m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager -dummyImage=bitnami/nginx:latest
go test -v $(MOD_FLAGS) -failfast -timeout 150m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager -dummyImage=bitnami/nginx:latest

e2e-local: build-linux build-wait build-util-linux
. ./scripts/build_local.sh
Expand Down Expand Up @@ -154,17 +165,13 @@ clean:
@rm -rf e2e.namespace


# Generate manifests for CRDs
# Copy CRD manifests
manifests: vendor
$(CONTROLLER_GEN) schemapatch:manifests=./deploy/chart/crds paths=./pkg/api/apis/operators/... output:dir=./deploy/chart/crds

$(YQ_INTERNAL) w --inplace deploy/chart/crds/0000_50_olm_03-clusterserviceversion.crd.yaml spec.validation.openAPIV3Schema.properties.spec.properties.install.properties.spec.properties.deployments.items.properties.spec.properties.template.properties.metadata.x-kubernetes-preserve-unknown-fields true
./scripts/copy_crds.sh

# Generate deepcopy, conversion, clients, listers, and informers
codegen:
# Deepcopy
$(CONTROLLER_GEN) object:headerFile=./boilerplate.go.txt paths=./pkg/api/apis/operators/...i
# Conversion, clients, listers, and informers
# Clients, listers, and informers
$(CODEGEN)

# Generate mock types.
Expand All @@ -182,11 +189,10 @@ verify-mockgen: mockgen diff
verify-manifests: manifests diff
verify: verify-codegen verify-mockgen verify-manifests


# before running release, bump the version in OLM_VERSION and push to master,
# then tag those builds in quay with the version in OLM_VERSION
release: ver=$(shell cat OLM_VERSION)
release:
release: manifests
docker pull quay.io/operator-framework/olm:$(ver)
$(MAKE) target=upstream ver=$(ver) quickstart=true package
$(MAKE) target=ocp ver=$(ver) package
Expand Down Expand Up @@ -220,3 +226,4 @@ endif
run-console-local:
@echo Running script to run the OLM console locally:
. ./scripts/run_console_local.sh

50 changes: 25 additions & 25 deletions cmd/olm/cleanup.go
@@ -1,10 +1,9 @@
package main

import (
"context"
"time"

"k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"

"github.com/sirupsen/logrus"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -14,8 +13,9 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
apiregv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
"k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
Expand Down Expand Up @@ -88,53 +88,53 @@ func waitForDelete(checkResource checkResourceFunc, deleteResource deleteResourc

func checkClusterServiceVersion(crc versioned.Interface, name string) checkResourceFunc {
return func() error {
_, err := crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Get(name, metav1.GetOptions{})
_, err := crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Get(context.TODO(), 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))
return crc.OperatorsV1alpha1().ClusterServiceVersions(*namespace).Delete(context.TODO(), name, *metav1.NewDeleteOptions(0))
}
}

func checkSubscription(crc versioned.Interface, name string) checkResourceFunc {
return func() error {
_, err := crc.OperatorsV1alpha1().Subscriptions(*namespace).Get(name, metav1.GetOptions{})
_, err := crc.OperatorsV1alpha1().Subscriptions(*namespace).Get(context.TODO(), 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))
return crc.OperatorsV1alpha1().Subscriptions(*namespace).Delete(context.TODO(), 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{})
_, err := c.KubernetesInterface().CoreV1().ConfigMaps(*namespace).Get(context.TODO(), 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))
return c.KubernetesInterface().CoreV1().ConfigMaps(*namespace).Delete(context.TODO(), name, *metav1.NewDeleteOptions(0))
}
}

func checkCatalogSource(crc versioned.Interface, name string) checkResourceFunc {
return func() error {
_, err := crc.OperatorsV1alpha1().CatalogSources(*namespace).Get(name, metav1.GetOptions{})
_, err := crc.OperatorsV1alpha1().CatalogSources(*namespace).Get(context.TODO(), 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))
return crc.OperatorsV1alpha1().CatalogSources(*namespace).Delete(context.TODO(), name, *metav1.NewDeleteOptions(0))
}
}

Expand All @@ -145,7 +145,7 @@ func deleteCatalogSource(crc versioned.Interface, name string) deleteResourceFun
// OwnerReference, and in cases where OLM is updated, they must be removed to prevent erroneous deletion of OLM's self-hosted components.
func cleanupOwnerReferences(c operatorclient.ClientInterface, crc versioned.Interface) error {
listOpts := metav1.ListOptions{}
csvs, err := crc.OperatorsV1alpha1().ClusterServiceVersions(metav1.NamespaceAll).List(listOpts)
csvs, err := crc.OperatorsV1alpha1().ClusterServiceVersions(metav1.NamespaceAll).List(context.TODO(), listOpts)
if err != nil {
return err
}
Expand All @@ -162,26 +162,26 @@ func cleanupOwnerReferences(c operatorclient.ClientInterface, crc versioned.Inte
objs = append(objs, &obj)
}

clusterRoles, _ := c.KubernetesInterface().RbacV1().ClusterRoles().List(listOpts)
clusterRoles, _ := c.KubernetesInterface().RbacV1().ClusterRoles().List(context.TODO(), listOpts)
for _, obj := range clusterRoles.Items {
objs = append(objs, &obj)
}

clusterRoleBindings, _ := c.KubernetesInterface().RbacV1().ClusterRoleBindings().List(listOpts)
clusterRoleBindings, _ := c.KubernetesInterface().RbacV1().ClusterRoleBindings().List(context.TODO(), listOpts)
for _, obj := range clusterRoleBindings.Items {
objs = append(objs, &obj)
}

roles, _ := c.KubernetesInterface().RbacV1().Roles(metav1.NamespaceAll).List(listOpts)
roles, _ := c.KubernetesInterface().RbacV1().Roles(metav1.NamespaceAll).List(context.TODO(), listOpts)
for _, obj := range roles.Items {
objs = append(objs, &obj)
}
roleBindings, _ := c.KubernetesInterface().RbacV1().RoleBindings(metav1.NamespaceAll).List(listOpts)
roleBindings, _ := c.KubernetesInterface().RbacV1().RoleBindings(metav1.NamespaceAll).List(context.TODO(), listOpts)
for _, obj := range roleBindings.Items {
objs = append(objs, &obj)
}

apiServices, _ := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(listOpts)
apiServices, _ := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(context.TODO(), listOpts)
for _, obj := range apiServices.Items {
objs = append(objs, &obj)
}
Expand All @@ -198,32 +198,32 @@ func cleanupOwnerReferences(c operatorclient.ClientInterface, crc versioned.Inte
switch v := obj.(type) {
case *v1alpha1.ClusterServiceVersion:
update = func() error {
_, err := crc.OperatorsV1alpha1().ClusterServiceVersions(v.GetNamespace()).Update(v)
_, err := crc.OperatorsV1alpha1().ClusterServiceVersions(v.GetNamespace()).Update(context.TODO(), v, metav1.UpdateOptions{})
return err
}
case *rbacv1.ClusterRole:
update = func() error {
_, err = c.KubernetesInterface().RbacV1().ClusterRoles().Update(v)
_, err = c.KubernetesInterface().RbacV1().ClusterRoles().Update(context.TODO(), v, metav1.UpdateOptions{})
return err
}
case *rbacv1.ClusterRoleBinding:
update = func() error {
_, err = c.KubernetesInterface().RbacV1().ClusterRoleBindings().Update(v)
_, err = c.KubernetesInterface().RbacV1().ClusterRoleBindings().Update(context.TODO(), v, metav1.UpdateOptions{})
return err
}
case *rbacv1.Role:
update = func() error {
_, err = c.KubernetesInterface().RbacV1().Roles(v.GetNamespace()).Update(v)
_, err = c.KubernetesInterface().RbacV1().Roles(v.GetNamespace()).Update(context.TODO(), v, metav1.UpdateOptions{})
return err
}
case *rbacv1.RoleBinding:
update = func() error {
_, err = c.KubernetesInterface().RbacV1().RoleBindings(v.GetNamespace()).Update(v)
_, err = c.KubernetesInterface().RbacV1().RoleBindings(v.GetNamespace()).Update(context.TODO(), v, metav1.UpdateOptions{})
return err
}
case *apiregv1.APIService:
update = func() error {
_, err = c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().Update(v)
_, err = c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().Update(context.TODO(), v, metav1.UpdateOptions{})
return err
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func crossNamespaceOwnerReferenceRemoval(kind string, uidNamespaces map[types.UI
// ensureAPIServiceLabels checks the labels of existing APIService objects to ensure ownership is set correctly.
// If the APIService label does not correspond to the expected packageserver owner the APIService labels are updated
func ensureAPIServiceLabels(c clientset.Interface) error {
apiService, err := c.ApiregistrationV1().APIServices().Get(olm.PackageserverName, metav1.GetOptions{})
apiService, err := c.ApiregistrationV1().APIServices().Get(context.TODO(), olm.PackageserverName, metav1.GetOptions{})
if err != nil && !k8serrors.IsNotFound(err) {
logrus.WithField("apiService", "packageserver").Debugf("get error: %s", err)
return err
Expand All @@ -280,7 +280,7 @@ func ensureAPIServiceLabels(c clientset.Interface) error {
if apiService.Labels[ownerutil.OwnerKey] != ownerutil.OwnerPackageServer {
apiService.Labels[ownerutil.OwnerKey] = ownerutil.OwnerPackageServer
update := func() error {
_, err := c.ApiregistrationV1().APIServices().Update(apiService)
_, err := c.ApiregistrationV1().APIServices().Update(context.TODO(), apiService, metav1.UpdateOptions{})
return err
}
if err := retry.RetryOnConflict(retry.DefaultBackoff, update); err != nil {
Expand Down
15 changes: 8 additions & 7 deletions cmd/olm/cleanup_test.go
@@ -1,6 +1,7 @@
package main

import (
"context"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -13,7 +14,7 @@ import (
apiregv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
apiregistrationfake "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
operatorsfake "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/fake"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
Expand Down Expand Up @@ -481,23 +482,23 @@ func TestCleanupOwnerReferences(t *testing.T) {
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.csvs, csvs.Items)

clusterRoles, err := c.KubernetesInterface().RbacV1().ClusterRoles().List(listOpts)
clusterRoles, err := c.KubernetesInterface().RbacV1().ClusterRoles().List(context.TODO(), listOpts)
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.clusterRoles, clusterRoles.Items)

clusterRoleBindings, err := c.KubernetesInterface().RbacV1().ClusterRoleBindings().List(listOpts)
clusterRoleBindings, err := c.KubernetesInterface().RbacV1().ClusterRoleBindings().List(context.TODO(), listOpts)
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.clusterRoleBindings, clusterRoleBindings.Items)

roles, err := c.KubernetesInterface().RbacV1().Roles(metav1.NamespaceAll).List(listOpts)
roles, err := c.KubernetesInterface().RbacV1().Roles(metav1.NamespaceAll).List(context.TODO(), listOpts)
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.roles, roles.Items)

roleBindings, err := c.KubernetesInterface().RbacV1().RoleBindings(metav1.NamespaceAll).List(listOpts)
roleBindings, err := c.KubernetesInterface().RbacV1().RoleBindings(metav1.NamespaceAll).List(context.TODO(), listOpts)
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.roleBindings, roleBindings.Items)

apiService, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(listOpts)
apiService, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(context.TODO(), listOpts)
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.apiServices, apiService.Items)
})
Expand Down Expand Up @@ -593,7 +594,7 @@ func TestCheckAPIServiceLabels(t *testing.T) {
c := operatorclient.NewClient(k8sClient, apiextensionsfake.NewSimpleClientset(), apiregistrationfake.NewSimpleClientset(tt.fields.apiServices...))
require.Equal(t, tt.expected.err, ensureAPIServiceLabels(c.ApiregistrationV1Interface()))

apiService, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(listOpts)
apiService, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(context.TODO(), listOpts)
require.NoError(t, err)
require.ElementsMatch(t, tt.expected.apiServices, apiService.Items)
})
Expand Down