Skip to content

Commit

Permalink
Merge pull request red-hat-storage#110 from rewantsoni/mac
Browse files Browse the repository at this point in the history
make development possible on different os/arch
  • Loading branch information
openshift-merge-bot[bot] authored Apr 3, 2024
2 parents d7091e0 + 4e6b703 commit 224d681
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 83 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bin/
testbin/

catalog
catalog.Dockerfile

# Created by https://www.toptal.com/developers/gitignore/api/go,vim,visualstudiocode,git
# Edit at https://www.toptal.com/developers/gitignore?templates=go,vim,visualstudiocode,git

Expand Down Expand Up @@ -74,6 +77,9 @@ tags
# Local History for Visual Studio Code
.history/

### IntelliJ ###
.idea

# Built Visual Studio Code Extensions
*.vsix

Expand Down
3 changes: 0 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ run:
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- ineffassign
- staticcheck
- structcheck
- unused
- varcheck
- revive
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ COPY controllers/ controllers/
COPY config/ config/
COPY pkg/ pkg/
COPY service/ service/
# Run tests and linting
RUN make go-test

# Build
RUN make go-build
Expand Down
25 changes: 12 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include hack/make-project-vars.mk
include hack/make-tools.mk
include hack/make-bundle-vars.mk


# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
Expand Down Expand Up @@ -55,15 +54,15 @@ vet: ## Run go vet against code.
go vet ./...

lint: ## Run golangci-lint against code.
docker run --rm -v $(PROJECT_DIR):/app:Z -w /app $(GO_LINT_IMG) golangci-lint run ./...
$(IMAGE_BUILD_CMD) run --rm -v $(PROJECT_DIR):/app -w /app $(GO_LINT_IMG) golangci-lint run ./...

godeps-update: ## Run go mod tidy & vendor
go mod tidy && go mod vendor

test-setup: godeps-update generate fmt vet ## Run setup targets for tests
test-setup: godeps-update generate fmt vet envtest ## Run setup targets for tests

go-test: ## Run go test against code.
./hack/go-test.sh
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(BIN_DIR) -p path)" go test -coverprofile cover.out `go list ./... | grep -v "e2e"`

test: test-setup go-test ## Run go unit tests.

Expand All @@ -82,11 +81,11 @@ go-build: ## Run go build against code.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

container-build: test-setup ## Build container image with the manager.
docker build -t ${IMG} .
container-build: test ## Build container image with the manager.
$(IMAGE_BUILD_CMD) build --platform="linux/amd64" -t ${IMG} .

container-push: ## Push container image with the manager.
docker push ${IMG}
$(IMAGE_BUILD_CMD) push ${IMG}

##@ Deployment

Expand Down Expand Up @@ -128,27 +127,27 @@ bundle: manifests kustomize operator-sdk yq ## Generate bundle manifests and met
--patch '[{"op": "replace", "path": "/spec/replaces", "value": "$(REPLACES)"}]'
$(KUSTOMIZE) build $(MANIFEST_PATH) | sed "s|STATUS_REPORTER_IMAGE_VALUE|$(IMG)|g" | awk '{print}'| \
$(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) --extra-service-accounts="$$($(KUSTOMIZE) build $(MANIFEST_PATH) | $(YQ) 'select(.kind == "ServiceAccount") | .metadata.name' -N | paste -sd "," -)"
sed -i "s|packageName:.*|packageName: ${CSI_ADDONS_PACKAGE_NAME}|g" "config/metadata/dependencies.yaml"
sed -i "s|version:.*|version: "${CSI_ADDONS_PACKAGE_VERSION}"|g" "config/metadata/dependencies.yaml"
yq -i '.dependencies[0].value.packageName = "'${CSI_ADDONS_PACKAGE_NAME}'"' config/metadata/dependencies.yaml
yq -i '.dependencies[0].value.version = "'${CSI_ADDONS_PACKAGE_VERSION}'"' config/metadata/dependencies.yaml
cp config/metadata/* bundle/metadata/
$(OPERATOR_SDK) bundle validate ./bundle

.PHONY: bundle-build
bundle-build: bundle ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
$(IMAGE_BUILD_CMD) build --platform="linux/amd64" -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
docker push $(BUNDLE_IMG)
$(IMAGE_BUILD_CMD) push $(BUNDLE_IMG)

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --permissive --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
./hack/build-catalog.sh

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
docker push $(CATALOG_IMG)
$(IMAGE_BUILD_CMD) push $(CATALOG_IMG)
42 changes: 26 additions & 16 deletions bundle/manifests/ocs-client-operator-csi-images_v1_configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@ apiVersion: v1
data:
csi-images.yaml: |
---
- version: v4.11
- version: v4.14
containerImages:
provisionerImageURL: "registry.k8s.io/sig-storage/csi-provisioner:v3.3.0"
attacherImageURL: "registry.k8s.io/sig-storage/csi-attacher:v4.0.0"
resizerImageURL: "registry.k8s.io/sig-storage/csi-resizer:v1.6.0"
snapshotterImageURL: "registry.k8s.io/sig-storage/csi-snapshotter:v6.1.0"
driverRegistrarImageURL: "registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.5.1"
cephCSIImageURL: "quay.io/cephcsi/cephcsi:v3.7.2"
csiaddonsImageURL: "quay.io/csiaddons/k8s-sidecar:v0.5.0"
provisionerImageURL: "registry.k8s.io/sig-storage/csi-provisioner:v4.0.0"
attacherImageURL: "registry.k8s.io/sig-storage/csi-attacher:v4.5.0"
resizerImageURL: "registry.k8s.io/sig-storage/csi-resizer:v1.10.0"
snapshotterImageURL: "registry.k8s.io/sig-storage/csi-snapshotter:v7.0.1"
driverRegistrarImageURL: "registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.10.0"
cephCSIImageURL: "quay.io/cephcsi/cephcsi:v3.10.2"
csiaddonsImageURL: "quay.io/csiaddons/k8s-sidecar:v0.8.0"
- version: v4.12
- version: v4.15
containerImages:
provisionerImageURL: "registry.k8s.io/sig-storage/csi-provisioner:v3.3.0"
attacherImageURL: "registry.k8s.io/sig-storage/csi-attacher:v4.0.0"
resizerImageURL: "registry.k8s.io/sig-storage/csi-resizer:v1.6.0"
snapshotterImageURL: "registry.k8s.io/sig-storage/csi-snapshotter:v6.1.0"
driverRegistrarImageURL: "registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.5.1"
cephCSIImageURL: "quay.io/cephcsi/cephcsi:v3.7.2"
csiaddonsImageURL: "quay.io/csiaddons/k8s-sidecar:v0.5.0"
provisionerImageURL: "registry.k8s.io/sig-storage/csi-provisioner:v4.0.0"
attacherImageURL: "registry.k8s.io/sig-storage/csi-attacher:v4.5.0"
resizerImageURL: "registry.k8s.io/sig-storage/csi-resizer:v1.10.0"
snapshotterImageURL: "registry.k8s.io/sig-storage/csi-snapshotter:v7.0.1"
driverRegistrarImageURL: "registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.10.0"
cephCSIImageURL: "quay.io/cephcsi/cephcsi:v3.10.2"
csiaddonsImageURL: "quay.io/csiaddons/k8s-sidecar:v0.8.0"
- version: v4.16
containerImages:
provisionerImageURL: "registry.k8s.io/sig-storage/csi-provisioner:v4.0.0"
attacherImageURL: "registry.k8s.io/sig-storage/csi-attacher:v4.5.0"
resizerImageURL: "registry.k8s.io/sig-storage/csi-resizer:v1.10.0"
snapshotterImageURL: "registry.k8s.io/sig-storage/csi-snapshotter:v7.0.1"
driverRegistrarImageURL: "registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.10.0"
cephCSIImageURL: "quay.io/cephcsi/cephcsi:v3.10.2"
csiaddonsImageURL: "quay.io/csiaddons/k8s-sidecar:v0.8.0"
kind: ConfigMap
metadata:
name: ocs-client-operator-csi-images
11 changes: 8 additions & 3 deletions bundle/manifests/ocs.openshift.io_storageclassclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: storageclassclaims.ocs.openshift.io
spec:
Expand Down Expand Up @@ -73,6 +73,9 @@ spec:
- storageClient
- type
type: object
x-kubernetes-validations:
- message: spec is immutable
rule: oldSelf == self
status:
description: StorageClassClaimStatus defines the observed state of StorageClassClaim
properties:
Expand All @@ -83,6 +86,8 @@ spec:
type: string
type: array
type: object
required:
- spec
type: object
served: true
storage: true
Expand All @@ -92,5 +97,5 @@ status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
conditions: null
storedVersions: null
6 changes: 3 additions & 3 deletions bundle/manifests/ocs.openshift.io_storageclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: storageclients.ocs.openshift.io
spec:
Expand Down Expand Up @@ -72,5 +72,5 @@ status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
conditions: null
storedVersions: null
8 changes: 4 additions & 4 deletions bundle/metadata/dependencies.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- type: olm.package
value:
packageName: csi-addons
version: 0.5.0
- type: olm.package
value:
packageName: csi-addons
version: 0.5.0
8 changes: 4 additions & 4 deletions config/metadata/dependencies.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- type: olm.package
value:
packageName: csi-addons
version: 0.5.0
- type: olm.package
value:
packageName: csi-addons
version: 0.5.0
36 changes: 36 additions & 0 deletions hack/build-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

rm -rf catalog
rm -rf catalog.Dockerfile

mkdir catalog

${OPM} render --output=yaml ${BUNDLE_IMG} > catalog/ocs-client-bundle.yaml
${OPM} render --output=yaml ${CSI_ADDONS_BUNDLE_IMG} > catalog/csi-adddons-bundle.yaml

cat << EOF >> catalog/index.yaml
---
defaultChannel: alpha
name: $IMAGE_NAME
schema: olm.package
---
schema: olm.channel
package: ocs-client-operator
name: alpha
entries:
- name: $IMAGE_NAME.v$VERSION
---
defaultChannel: alpha
name: $CSI_ADDONS_PACKAGE_NAME
schema: olm.package
---
schema: olm.channel
package: csi-addons
name: alpha
entries:
- name: $CSI_ADDONS_PACKAGE_NAME.v$CSI_ADDONS_PACKAGE_VERSION
EOF

${OPM} validate catalog
${OPM} generate dockerfile catalog
${IMAGE_BUILD_CMD} build --platform="linux/amd64" -t ${CATALOG_IMG} -f catalog.Dockerfile .
20 changes: 0 additions & 20 deletions hack/go-test-setup.sh

This file was deleted.

9 changes: 0 additions & 9 deletions hack/go-test.sh

This file was deleted.

2 changes: 1 addition & 1 deletion hack/make-bundle-vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ endif

# csi-addons dependencies
CSI_ADDONS_PACKAGE_NAME ?= csi-addons
CSI_ADDONS_PACKAGE_VERSION ?= "0.5.0"
CSI_ADDONS_PACKAGE_VERSION ?= 0.5.0

## CSI driver images
# The following variables define the default CSI container images to deploy
Expand Down
15 changes: 12 additions & 3 deletions hack/make-project-vars.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
PROJECT_DIR := $(PWD)
BIN_DIR := $(PROJECT_DIR)/bin
ENVTEST_ASSETS_DIR := $(PROJECT_DIR)/testbin

GOROOT ?= $(shell go env GOROOT)
GOBIN ?= $(BIN_DIR)
GOOS ?= linux
GOARCH ?= amd64
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

GO_LINT_IMG_LOCATION ?= golangci/golangci-lint
GO_LINT_IMG_TAG ?= v1.56.2
GO_LINT_IMG ?= $(GO_LINT_IMG_LOCATION):$(GO_LINT_IMG_TAG)

ENVTEST_K8S_VERSION?=1.26

ifeq ($(IMAGE_BUILD_CMD),)
IMAGE_BUILD_CMD := $(shell command -v docker || echo "")
endif

ifeq ($(IMAGE_BUILD_CMD),)
IMAGE_BUILD_CMD := $(shell command -v podman || echo "")
endif
8 changes: 6 additions & 2 deletions hack/make-tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
define go-get-tool
@[ -f $(1) ] || { \
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
$(shell GOBIN=$(PROJECT_DIR)/bin go install $(2)) \
}
endef

Expand Down Expand Up @@ -31,4 +31,8 @@ operator-sdk: ## Download operator-sdk locally if necessary.
.PHONY: opm
OPM = $(BIN_DIR)/opm
opm: ## Download opm locally if necessary.
@./hack/get-tool.sh $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$(GOOS)-$(GOARCH)-opm
@./hack/get-tool.sh $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.20.0/$(GOOS)-$(GOARCH)-opm

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

0 comments on commit 224d681

Please sign in to comment.