Skip to content

Commit

Permalink
Updates for operator sdk v1.28 (#45)
Browse files Browse the repository at this point in the history
* required changes to update operator sdk

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* ginkgo v2 migration changes.

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* remove extra ENVTEST definition

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* dependencies updated to match operator sdk v1.28 requirements

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* refactoring controllers package to internal/controller package as part of go/v4 prep changes in operator sdk v1.28

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* bump gcr.io/kubebuilder/kube-rbac-proxy from v0.13.0 to v0.13.1 as part of operator sdk v1.28 changes

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* refactoring main.go to cmd/main.go as part of go/v4 prep changes in operator sdk v1.28

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* update header under integration test source

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* update go version from 1.18 to 1.19 under ci workflows

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* import admissionv1beta1 changed to admissionv1 as part of operator sdk v1.28 changes

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* update license header and boilerplate files

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* rbac service account role bindings fixed with labels added

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* security context for manager container updated.

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* recent changes applied to bundle manifests

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* service account renamed to fix name prefix issue.

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* fixed envtest binary name

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* fixed relative path to 'config/crd/bases' under controller test suite

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* controller-gen deepcopy source update to header

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* fixup docker-buildx rule

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* CHANGELOG added

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* included change log documenting as part of PR acceptance criteria

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* target os is always linux

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* sa changed to service-account

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* bundle csv update

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* go v4 project structure changes reverted.

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* restore unset GOFLAGS

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* use operator namespace when waiting for operator pod to run for integration test suite

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* add registry operator deploy command to openshift integration test script

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* add touch command in Makefile to create junit report if does not exist

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* add docker-buildx optional step to build and run the operator instruction under CONTRIBUTING.md

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

* make /tmp/artifacts directory if does not exist before running integration tests

Signed-off-by: Michael Valdron <mvaldron@redhat.com>

---------

Signed-off-by: Michael Valdron <mvaldron@redhat.com>
  • Loading branch information
michael-valdron authored Aug 31, 2023
1 parent 9ac9961 commit fd4aacc
Show file tree
Hide file tree
Showing 55 changed files with 1,385 additions and 194 deletions.
8 changes: 8 additions & 0 deletions .ci/openshift_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ make controller-gen
make install-cert
# wait one minute for cert manager to get set up
sleep 60
# need to deploy the registry operator to run tests
# ToDo: Remove later after the addition of readiness check, integration tests can deploy the operator however tests fail if
# pod is not ready in time.
make install && make deploy
# wait 15 seconds for registry operator to get set up
sleep 15

# run integration test suite
make test-integration
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Fixes #?

**PR acceptance criteria**:

- [ ] Change Log
- Are all your changes documented under the [upcoming release](../CHANGELOG.md#unreleased) entry?
- [ ] Test Coverage
- Are your changes sufficiently tested, and are any applicable test cases added or updated to cover your changes?
- [ ] Gosec scans
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19
-
name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19
- name: Run tests
run: make test
- name: Codecov
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- [devfile/api#1106](https://github.com/devfile/api/issues/1106)
Registry operator should be in sync with operator SDK releases
- Addition of `CHANGELOG.md`

### Changed

- [devfile/api#1106](https://github.com/devfile/api/issues/1106)
Registry operator should be in sync with operator SDK releases
- Syncs changes up to operator sdk v1.28
- [v1.28.0 changes](https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.28.0/)
- [v1.25.0 changes](https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.25.0/)
- [v1.23.0 changes](https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.23.0/)
- [devfile/api#881](https://github.com/devfile/api/issues/881)
Update Ginkgo version in registry operator

### Fixed
- [devfile/api#1106](https://github.com/devfile/api/issues/1106)
Registry operator should be in sync with operator SDK releases
- Registry operator service account changed from `default` to `service-account` to fix permissions error for creating leader election leases
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ You can tag Devfile Registry related issues with the `/area registry` text in yo

4. Run `make docker-push` to push the devfile registry operator image.

5. Run `make install-cert` to install the cert-manager.
5. (Optional, **docker only**) Run `make docker-buildx` to build and push the devfile registry operator multi-architecture image

6. Run `make install` to install the CRDs.
6. Run `make install-cert` to install the cert-manager.

7. Run `make deploy` to deploy the operator.
7. Run `make install` to install the CRDs.

8. Run `make deploy` to deploy the operator.

### Testing your Changes

Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM golang:1.19 as builder
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -16,7 +17,7 @@ COPY controllers/ controllers/
COPY pkg/ pkg/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o manager main.go

ARG ENABLE_WEBHOOKS=true
ENV ENABLE_WEBHOOKS=${ENABLE_WEBHOOKS}
Expand Down
118 changes: 61 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
IMG ?= quay.io/devfile/registry-operator:next
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26

# Controller tools version number
CONTROLLER_TOOLS_VERSION ?= v0.9.2
# Kustomize version number
KUSTOMIZE_VERSION ?= v3.8.7

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -67,32 +70,48 @@ all: build
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build Dependencies

## Local binary path
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

##@ Development

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test `go list ./... | grep -v /tests/` -coverprofile cover.out -v
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -timeout=1h `go list ./... | grep -v /tests/` -coverprofile cover.out -v

### test-integration: runs integration tests on the cluster set in context.
.PHONY: test-integration
test-integration:
CGO_ENABLED=0 go test -v -c -o bin/devfileregistry-operator-integration ./tests/integration/cmd/devfileregistry_test.go
./bin/devfileregistry-operator-integration
CGO_ENABLED=0 go test -v -c -o $(LOCALBIN)/devfileregistry-operator-integration ./tests/integration/cmd/devfileregistry_test.go
# Create junit report output file if does not exist
mkdir -p /tmp/artifacts && touch /tmp/artifacts/junit-devfileregistry-operator.xml
$(LOCALBIN)/devfileregistry-operator-integration -ginkgo.fail-fast --ginkgo.junit-report=/tmp/artifacts/junit-devfileregistry-operator.xml

##@ Build

.PHONY: build
manager: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
.PHONY: build manager
manager: manifests generate fmt vet ## Build manager binary.
go build -o $(LOCALBIN)/manager ./cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
go run ./cmd/main.go

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

### check_fmt: Checks the formatting on files in repo
.PHONY: check_fmt
check_fmt:
ifeq ($(shell command -v goimports 2> /dev/null),)
$(error "goimports must be installed for this rule" && exit 1)
Expand All @@ -113,6 +132,7 @@ fmt: ## Run go fmt against code.
go fmt ./...

### fmt_license: ensure license header is set on all files
.PHONY: fmt_license
fmt_license:
ifneq ($(shell command -v addlicense 2> /dev/null),)
@echo 'addlicense -v -f license_header.txt **/*.go'
Expand All @@ -139,30 +159,39 @@ docker-build:
docker-push:
docker push ${IMG}

# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=quay.io/devfile/registry-operator:next). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=quay.io/<user>/registry-operator:next than the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
# **docker-buildx does not work with podman**
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name registry-operator-builder
docker buildx use registry-operator-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross $(shell pwd)
- docker buildx rm registry-operator-builder
rm Dockerfile.cross

.PHONY: install-cert
install-cert: ## Install cert manager for webhooks
$(K8S_CLI) apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml

.PHONY: uninstall-cert
uninstall-cert:
$(K8S_CLI) delete -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif


.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN)
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

##@ Deployment

Expand All @@ -183,41 +212,16 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | $(K8S_CLI) delete -f -

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE)
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
GOFLAGS="" go install sigs.k8s.io/kustomize/kustomize/v4@v4.5.5 ;\
go mod vendor ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-get-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) GOFLAGS="" go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The Devfile Registry operator manages the lifecycle of the following custom reso

Issue tracking repo: https://github.com/devfile/api with label area/registry

## Changelog

Access the [CHANGELOG.md](CHANGELOG.md) here.

## Requirements

Deployment cluster must meet one of the following criteria:
Expand Down Expand Up @@ -64,6 +68,7 @@ Some of the rules supported by the makefile:
| kustomize | install the kustomize tool, used by other commands |
| docker-build | build registry operator docker image |
| docker-push | push registry operator docker image |
| docker-buildx | build & push registry operator docker image for all supported architectures \(**does not work with podman**\) |
| deploy | deploy operator to cluster |
| undeploy | undeploy operator from cluster |
| install | create the devfile registry CRDs on the cluster |
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/clusterdevfileregistrieslist_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"

. "github.com/devfile/registry-operator/pkg/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/devfileregistrieslist_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"

. "github.com/devfile/registry-operator/pkg/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/devfileregistry_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"

. "github.com/devfile/registry-operator/pkg/test"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

admissionv1beta1 "k8s.io/api/admission/v1beta1"
Expand Down Expand Up @@ -158,7 +158,7 @@ var _ = BeforeSuite(func() {
return nil
}).Should(Succeed())

}, 60)
})

var _ = AfterSuite(func() {
// delete the devfileregistries namespace
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ kind: Service
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: devfileregistry-operator
app.kubernetes.io/instance: controller-manager-metrics-service
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: service
app.kubernetes.io/part-of: devfileregistry-operator
control-plane: controller-manager
name: registry-operator-controller-manager-metrics-service
spec:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: devfileregistry-operator
app.kubernetes.io/instance: metrics-reader
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: clusterrole
app.kubernetes.io/part-of: devfileregistry-operator
name: registry-operator-metrics-reader
rules:
- nonResourceURLs:
Expand Down
Loading

0 comments on commit fd4aacc

Please sign in to comment.