Skip to content

Commit

Permalink
Migrated to go/v4 project layout
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Aug 13, 2024
1 parent 07f1e54 commit bb8b076
Show file tree
Hide file tree
Showing 66 changed files with 27,971 additions and 34,424 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
- name: Setup-go
uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.22
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
version: v1.57
args: --timeout=5m
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.21 AS builder
FROM --platform=$BUILDPLATFORM golang:1.22 AS builder

# OS and Arch args
ARG TARGETOS
Expand All @@ -14,14 +14,14 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/controller/ internal/controller/
COPY pkg/ pkg/
COPY errors/ errors/

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

# Base image
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
Expand Down
87 changes: 63 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ endif
IMG ?= controller:latest

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26
ENVTEST_K8S_VERSION = 1.29.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -129,17 +129,14 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.54.0

.PHONY: golanci-lint
golanci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI_LINT_VERSION)

.PHONY: go-lint
go-lint: golanci-lint ## Run golangci-lint against code.
$(GOLANGCI_LINT) run

.PHONY: go-lint-fix
go-lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

.PHONY: all-test
all-test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" cd $(shell pwd)/test; go run github.com/onsi/ginkgo/v2/ginkgo -coverprofile cover.out -r --keep-going -show-node-events -v -timeout=12h0m0s --junit-report="junit.xml" -- ${ARGS}
Expand All @@ -166,11 +163,11 @@ restore-test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build -o bin/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: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
Expand All @@ -189,6 +186,7 @@ docker-buildx-openshift: ## Build and push docker image for the manager for open
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}

##@ Deployment

ifndef ignore-not-found
Expand Down Expand Up @@ -237,30 +235,71 @@ $(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.7
CONTROLLER_TOOLS_VERSION ?= v0.12.1
KUSTOMIZE_VERSION ?= v5.3.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= release-0.17
GOLANGCI_LINT_VERSION ?= v1.57.2
# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.36.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef

.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (, $(shell which operator-sdk 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPERATOR_SDK)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK) ;\
}
else
OPERATOR_SDK = $(shell which operator-sdk)
endif
endif

.PHONY: enable-pre-commit
enable-pre-commit:
Expand All @@ -278,11 +317,11 @@ submodules: ## Pull and update git submodules recursively
.PHONY: bundle
bundle: manifests kustomize
rm -rf $(ROOT_DIR)/bundle.Dockerfile $(BUNDLE_DIR)
operator-sdk generate kustomize manifests -q
$(OPERATOR_SDK) generate kustomize manifests -q
cd $(ROOT_DIR)/config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
cd $(ROOT_DIR)/config/manifests/bases && $(KUSTOMIZE) edit set annotation createdAt:$(DATE)
cd $(ROOT_DIR) && $(KUSTOMIZE) build $(OVERLAYS_DIR) | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS) --output-dir $(BUNDLE_DIR)
operator-sdk bundle validate $(BUNDLE_DIR)
cd $(ROOT_DIR) && $(KUSTOMIZE) build $(OVERLAYS_DIR) | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) --output-dir $(BUNDLE_DIR)
$(OPERATOR_SDK) bundle validate $(BUNDLE_DIR)
sed -i "s@containerImage: controller:latest@containerImage: $(IMG)@g" $(BUNDLE_DIR)/manifests/aerospike-kubernetes-operator.clusterserviceversion.yaml
sed -i "/^FROM.*/a LABEL com.redhat.openshift.versions="$(OPENSHIFT_VERSION)"" $(ROOT_DIR)/bundle.Dockerfile; \
sed -i "/^FROM.*/a LABEL com.redhat.delivery.operator.bundle=true" $(ROOT_DIR)/bundle.Dockerfile; \
Expand Down
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
domain: aerospike.com
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/aerospikebackup_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (

"github.com/abhishekdwivedi3060/aerospike-backup-service/pkg/model"
asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
"github.com/aerospike/aerospike-kubernetes-operator/controllers/common"
"github.com/aerospike/aerospike-kubernetes-operator/internal/controller/common"
)

// log is for logging in this package.
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/aerospikerestore_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sigs.k8s.io/yaml"

"github.com/abhishekdwivedi3060/aerospike-backup-service/pkg/model"
"github.com/aerospike/aerospike-kubernetes-operator/controllers/common"
"github.com/aerospike/aerospike-kubernetes-operator/internal/controller/common"
)

// log is for logging in this package.
Expand Down
31 changes: 17 additions & 14 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
crClient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/aerospike/aerospike-management-lib/asconfig"

asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
asdbv1beta1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1beta1"
"github.com/aerospike/aerospike-kubernetes-operator/controllers/backup"
backupservice "github.com/aerospike/aerospike-kubernetes-operator/controllers/backup-service"
"github.com/aerospike/aerospike-kubernetes-operator/internal/controller/backup"
backupservice "github.com/aerospike/aerospike-kubernetes-operator/internal/controller/backup-service"
"github.com/aerospike/aerospike-management-lib/asconfig"

// +kubebuilder:scaffold:imports
"github.com/aerospike/aerospike-kubernetes-operator/controllers/cluster"
"github.com/aerospike/aerospike-kubernetes-operator/controllers/restore"
"github.com/aerospike/aerospike-kubernetes-operator/internal/controller/cluster"
"github.com/aerospike/aerospike-kubernetes-operator/internal/controller/restore"
"github.com/aerospike/aerospike-kubernetes-operator/pkg/configschema"
)

Expand Down Expand Up @@ -86,14 +86,17 @@ func main() {
if strings.Contains(watchNs, ",") {
nsList := strings.Split(watchNs, ",")

var newNsList []string
namespaces := make(map[string]cache.Config)

for _, ns := range nsList {
newNsList = append(newNsList, strings.TrimSpace(ns))
namespaces[strings.TrimSpace(ns)] = cache.Config{}
}

options.Cache.Namespaces = newNsList
options.Cache.DefaultNamespaces = namespaces
} else {
options.Cache.Namespaces = []string{watchNs}
options.Cache.DefaultNamespaces = map[string]cache.Config{
watchNs: {},
}
}

kubeConfig := ctrl.GetConfigOrDie()
Expand Down Expand Up @@ -142,7 +145,7 @@ func main() {
Client: client,
KubeClient: kubeClient,
KubeConfig: kubeConfig,
Log: ctrl.Log.WithName("controllers").WithName("AerospikeCluster"),
Log: ctrl.Log.WithName("controller").WithName("AerospikeCluster"),
Scheme: mgr.GetScheme(),
Recorder: eventBroadcaster.NewRecorder(
mgr.GetScheme(), v1.EventSource{Component: "aerospikeCluster-controller"},
Expand All @@ -163,7 +166,7 @@ func main() {
if err = (&backupservice.AerospikeBackupServiceReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("AerospikeBackupService"),
Log: ctrl.Log.WithName("controller").WithName("AerospikeBackupService"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AerospikeBackupService")
os.Exit(1)
Expand All @@ -177,7 +180,7 @@ func main() {
if err = (&backup.AerospikeBackupReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("AerospikeBackup"),
Log: ctrl.Log.WithName("controller").WithName("AerospikeBackup"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AerospikeBackup")
os.Exit(1)
Expand All @@ -191,7 +194,7 @@ func main() {
if err = (&restore.AerospikeRestoreReconciler{
Client: client,
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("AerospikeRestore"),
Log: ctrl.Log.WithName("controller").WithName("AerospikeRestore"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AerospikeRestore")
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ metadata:
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
namespace: system
spec:
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
# SERVICE_NAME_PLACEHOLDER and SERVICE_NAMESPACE_PLACEHOLDER will be substituted by kustomize
dnsNames:
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
- SERVICE_NAME_PLACEHOLDER.SERVICE_NAMESPACE_PLACEHOLDER.svc
- SERVICE_NAME_PLACEHOLDER.SERVICE_NAMESPACE_PLACEHOLDER.svc.cluster.local
issuerRef:
kind: Issuer
name: selfsigned-issuer
Expand Down
37 changes: 21 additions & 16 deletions config/crd/bases/asdb.aerospike.com_aerospikebackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
controller-gen.kubebuilder.io/version: v0.14.0
name: aerospikebackups.asdb.aerospike.com
spec:
group: asdb.aerospike.com
Expand All @@ -30,14 +30,19 @@ spec:
description: AerospikeBackup is the Schema for the aerospikebackup API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
Expand All @@ -46,9 +51,9 @@ spec:
for a given AerospikeCluster
properties:
backupService:
description: BackupService is the backup service reference i.e. name
and namespace. It is used to communicate to the backup service to
trigger backups. This field is immutable
description: |-
BackupService is the backup service reference i.e. name and namespace.
It is used to communicate to the backup service to trigger backups. This field is immutable
properties:
name:
description: Backup service name
Expand All @@ -61,9 +66,9 @@ spec:
- namespace
type: object
config:
description: 'Config is the free form configuration for the backup
in YAML format. This config is used to trigger backups. It includes:
aerospike-cluster, backup-routines.'
description: |-
Config is the free form configuration for the backup in YAML format.
This config is used to trigger backups. It includes: aerospike-cluster, backup-routines.
type: object
x-kubernetes-preserve-unknown-fields: true
onDemandBackups:
Expand Down Expand Up @@ -110,9 +115,9 @@ spec:
- namespace
type: object
config:
description: 'Config is the configuration for the backup in YAML format.
This config is used to trigger backups. It includes: aerospike-cluster,
backup-routines.'
description: |-
Config is the configuration for the backup in YAML format.
This config is used to trigger backups. It includes: aerospike-cluster, backup-routines.
type: object
x-kubernetes-preserve-unknown-fields: true
onDemandBackups:
Expand Down
Loading

0 comments on commit bb8b076

Please sign in to comment.