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

Updates for operator sdk v1.28 #45

Merged
merged 31 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bfb4d73
required changes to update operator sdk
michael-valdron Jul 28, 2023
643b58b
ginkgo v2 migration changes.
michael-valdron Jul 31, 2023
bb8bc77
remove extra ENVTEST definition
michael-valdron Jul 31, 2023
50cd96b
dependencies updated to match operator sdk v1.28 requirements
michael-valdron Aug 1, 2023
218322a
refactoring controllers package to internal/controller package as par…
michael-valdron Aug 1, 2023
6eb7007
bump gcr.io/kubebuilder/kube-rbac-proxy from v0.13.0 to v0.13.1 as pa…
michael-valdron Aug 1, 2023
238a584
refactoring main.go to cmd/main.go as part of go/v4 prep changes in o…
michael-valdron Aug 1, 2023
8609321
update header under integration test source
michael-valdron Aug 1, 2023
b5d3a1e
update go version from 1.18 to 1.19 under ci workflows
michael-valdron Aug 1, 2023
af47e6d
import admissionv1beta1 changed to admissionv1 as part of operator sd…
michael-valdron Aug 1, 2023
900037d
update license header and boilerplate files
michael-valdron Aug 2, 2023
fce2a27
rbac service account role bindings fixed with labels added
michael-valdron Aug 3, 2023
faa4416
security context for manager container updated.
michael-valdron Aug 3, 2023
8c1549e
recent changes applied to bundle manifests
michael-valdron Aug 3, 2023
accac00
service account renamed to fix name prefix issue.
michael-valdron Aug 26, 2023
c3102e5
fixed envtest binary name
michael-valdron Aug 27, 2023
dde89f5
fixed relative path to 'config/crd/bases' under controller test suite
michael-valdron Aug 27, 2023
438187f
controller-gen deepcopy source update to header
michael-valdron Aug 27, 2023
7ddba8b
fixup docker-buildx rule
michael-valdron Aug 27, 2023
f59074a
CHANGELOG added
michael-valdron Aug 28, 2023
a036e9d
included change log documenting as part of PR acceptance criteria
michael-valdron Aug 28, 2023
082b5c4
target os is always linux
michael-valdron Aug 28, 2023
23016bb
sa changed to service-account
michael-valdron Aug 28, 2023
d95d935
bundle csv update
michael-valdron Aug 28, 2023
df5e1e6
go v4 project structure changes reverted.
michael-valdron Aug 28, 2023
d2dcfc5
restore unset GOFLAGS
michael-valdron Aug 30, 2023
69c5f99
use operator namespace when waiting for operator pod to run for integ…
michael-valdron Aug 30, 2023
2c763a2
add registry operator deploy command to openshift integration test sc…
michael-valdron Aug 30, 2023
e1f6c87
add touch command in Makefile to create junit report if does not exist
michael-valdron Aug 30, 2023
604db86
add docker-buildx optional step to build and run the operator instruc…
michael-valdron Aug 30, 2023
ff9e578
make /tmp/artifacts directory if does not exist before running integr…
michael-valdron Aug 31, 2023
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
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
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved
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
Loading