Skip to content

Commit

Permalink
Build using K8s 1.28 and Go 1.20 (#616)
Browse files Browse the repository at this point in the history
* Update K8s dependencies
* Change Istio versions for tests
  • Loading branch information
thegridman committed Sep 12, 2023
1 parent c3dcaf9 commit 26c792f
Show file tree
Hide file tree
Showing 38 changed files with 532 additions and 1,609 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/istio-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
matrix:
istioVersion:
- latest
- 1.16.1
- 1.15.4
- 1.18.2
- 1.17.5

steps:
- uses: actions/checkout@v3
Expand Down
60 changes: 36 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COMPATIBLE_SELECTOR = control-plane=coherence
# The GitHub project URL
PROJECT_URL = https://github.com/oracle/coherence-operator

KUBERNETES_DOC_VERSION=v1.26
KUBERNETES_DOC_VERSION=v1.28

# ----------------------------------------------------------------------------------------------------------------------
# The Coherence image to use for deployments that do not specify an image
Expand Down Expand Up @@ -325,6 +325,7 @@ GOS = $(shell find . -type f -name "*.go" ! -name "*_test.go")
HELM_FILES = $(shell find helm-charts/coherence-operator -type f)
API_GO_FILES = $(shell find . -type f -name "*.go" ! -name "*_test.go" ! -name "zz*.go")
CRDV1_FILES = $(shell find ./config/crd -type f)
JAVA_FILES = $(shell find ./java -type f)

TEST_SSL_SECRET := coherence-ssl-secret

Expand Down Expand Up @@ -431,7 +432,7 @@ clean-tools: ## Cleans the locally downloaded build tools (i.e. need a new tool
.PHONY: build-operator
build-operator: $(BUILD_TARGETS)/build-operator ## Build the Coherence Operator image

$(BUILD_TARGETS)/build-operator: $(BUILD_BIN)/runner build-mvn coherence-cli
$(BUILD_TARGETS)/build-operator: $(BUILD_BIN)/runner $(BUILD_TARGETS)/java $(BUILD_TARGETS)/cli
docker build --no-cache --build-arg version=$(VERSION) \
--build-arg BASE_IMAGE=$(OPERATOR_BASE_IMAGE) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
Expand All @@ -448,7 +449,7 @@ $(BUILD_TARGETS)/build-operator: $(BUILD_BIN)/runner build-mvn coherence-cli
touch $(BUILD_TARGETS)/build-operator

.PHONY: build-operator-with-tools
build-operator-with-tools: $(BUILD_BIN)/runner build-mvn ## Build the Coherence Operator image on OL-8 with debug tools
build-operator-with-tools: $(BUILD_BIN)/runner $(BUILD_TARGETS)/java ## Build the Coherence Operator image on OL-8 with debug tools
mkdir -p $(BUILD_OUTPUT)/images || true
cat Dockerfile debug/Tools.Dockerfile > $(BUILD_OUTPUT)/images/Dockerfile
docker build --no-cache --build-arg version=$(VERSION) \
Expand All @@ -460,7 +461,7 @@ build-operator-with-tools: $(BUILD_BIN)/runner build-mvn ## Build the Coherence
. -t $(OPERATOR_IMAGE)

.PHONY: build-operator-debug
build-operator-debug: $(BUILD_BIN)/linux/amd64/runner-debug build-mvn ## Build the Coherence Operator image with the Delve debugger
build-operator-debug: $(BUILD_BIN)/linux/amd64/runner-debug $(BUILD_TARGETS)/java ## Build the Coherence Operator image with the Delve debugger
docker build --no-cache --build-arg version=$(VERSION) \
--build-arg BASE_IMAGE=$(OPERATOR_IMAGE_DELVE) \
--build-arg coherence_image=$(COHERENCE_IMAGE) \
Expand All @@ -486,7 +487,7 @@ build-operator-images: $(BUILD_TARGETS)/build-operator ## Build all operator ima
# Build the Operator Test images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-test-images
build-test-images: build-mvn build-client-image build-basic-test-image ## Build all of the test images
build-test-images: $(BUILD_TARGETS)/java build-client-image build-basic-test-image ## Build all of the test images
./mvnw -B -f java/operator-test-helidon package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE_HELIDON) $(MAVEN_BUILD_OPTS)
./mvnw -B -f java/operator-test-spring package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE_SPRING) $(MAVEN_BUILD_OPTS)
./mvnw -B -f java/operator-test-spring package spring-boot:build-image -DskipTests -Dcnbp-image-name=$(TEST_APPLICATION_IMAGE_SPRING_CNBP) $(MAVEN_BUILD_OPTS)
Expand All @@ -500,7 +501,7 @@ build-test-images: build-mvn build-client-image build-basic-test-image ## Build
# Build the basic Operator Test image
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-basic-test-image
build-basic-test-image: build-mvn ## Build the basic Operator test image
build-basic-test-image: $(BUILD_TARGETS)/java ## Build the basic Operator test image
./mvnw -B -f java/operator-test clean package jib:dockerBuild -DskipTests -Djib.to.image=$(TEST_APPLICATION_IMAGE) $(MAVEN_BUILD_OPTS) -Dcoherence.version=$(COHERENCE_IMAGE_TAG)

.PHONY: build-client-image
Expand Down Expand Up @@ -538,16 +539,20 @@ $(BUILD_BIN)/runner: $(BUILD_PROPS) $(GOS) $(BUILD_TARGETS)/generate $(BUILD_TAR
# Build the Java artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-mvn
build-mvn: ## Build the Java artefacts
build-mvn: $(BUILD_TARGETS)/java ## Build the Java artefacts

$(BUILD_TARGETS)/java: $(JAVA_FILES)
./mvnw -B -f java clean install -DskipTests $(MAVEN_BUILD_OPTS)
touch $(BUILD_TARGETS)/java


# ---------------------------------------------------------------------------
# Build the Coherence operator Helm chart and package it into a tar.gz
# ---------------------------------------------------------------------------
.PHONY: helm-chart
helm-chart: $(BUILD_PROPS) $(BUILD_HELM)/coherence-operator-$(VERSION).tgz ## Build the Coherence Operator Helm chart

$(BUILD_HELM)/coherence-operator-$(VERSION).tgz: $(BUILD_PROPS) $(HELM_FILES) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests kustomize
$(BUILD_HELM)/coherence-operator-$(VERSION).tgz: $(BUILD_PROPS) $(HELM_FILES) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests $(TOOLS_BIN)/kustomize
# Copy the Helm chart from the source location to the distribution folder
-mkdir -p $(BUILD_HELM)
cp -R ./helm-charts/coherence-operator $(BUILD_HELM)
Expand Down Expand Up @@ -587,7 +592,7 @@ manifests: $(BUILD_TARGETS)/manifests ## Generate the CustomResourceDefinition a
$(BUILD_TARGETS)/manifests: $(BUILD_PROPS) config/crd/bases/coherence.oracle.com_coherence.yaml docs/about/04_coherence_spec.adoc $(BUILD_MANIFESTS_PKG)
touch $(BUILD_TARGETS)/manifests

config/crd/bases/coherence.oracle.com_coherence.yaml: kustomize $(API_GO_FILES) controller-gen
config/crd/bases/coherence.oracle.com_coherence.yaml: $(TOOLS_BIN)/kustomize $(API_GO_FILES) $(TOOLS_BIN)/controller-gen
$(CONTROLLER_GEN) "crd:crdVersions={v1}" \
rbac:roleName=manager-role paths="{./api/...,./controllers/...}" \
output:crd:dir=config/crd/bases
Expand Down Expand Up @@ -621,7 +626,7 @@ generate: $(BUILD_TARGETS)/generate ## Run Kubebuilder code and configuration g
$(BUILD_TARGETS)/generate: $(BUILD_PROPS) $(BUILD_OUTPUT)/config.json api/v1/zz_generated.deepcopy.go
touch $(BUILD_TARGETS)/generate

api/v1/zz_generated.deepcopy.go: $(API_GO_FILES) controller-gen
api/v1/zz_generated.deepcopy.go: $(API_GO_FILES) $(TOOLS_BIN)/controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./api/..."

# ----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -787,7 +792,7 @@ stop: ## kill any locally running operator process
# Generate bundle manifests and metadata, then validate generated files.
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: bundle
bundle: $(BUILD_PROPS) ensure-sdk kustomize $(BUILD_TARGETS)/manifests ## Generate OLM bundle manifests and metadata, then validate generated files.
bundle: $(BUILD_PROPS) ensure-sdk $(TOOLS_BIN)/kustomize $(BUILD_TARGETS)/manifests ## Generate OLM bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
Expand Down Expand Up @@ -869,7 +874,7 @@ test-operator: $(BUILD_PROPS) $(BUILD_TARGETS)/manifests $(BUILD_TARGETS)/genera
# Build and test the Java artifacts
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: test-mvn
test-mvn: $(BUILD_OUTPUT)/certs build-mvn ## Run the Java artefact tests
test-mvn: $(BUILD_OUTPUT)/certs $(BUILD_TARGETS)/java ## Run the Java artefact tests
./mvnw -B -f java verify -Dtest.certs.location=$(BUILD_OUTPUT)/certs $(MAVEN_BUILD_OPTS)


Expand Down Expand Up @@ -1305,7 +1310,7 @@ deploy-and-wait: deploy wait-for-deploy ## Deploy the Coherence Operator and w
OPERATOR_HA ?= true

.PHONY: deploy
deploy: prepare-deploy create-namespace kustomize ## Deploy the Coherence Operator
deploy: prepare-deploy create-namespace $(TOOLS_BIN)/kustomize ## Deploy the Coherence Operator
ifneq (,$(WATCH_NAMESPACE))
cd $(BUILD_DEPLOY)/manager && $(KUSTOMIZE) edit add configmap env-vars --from-literal WATCH_NAMESPACE=$(WATCH_NAMESPACE)
endif
Expand All @@ -1322,11 +1327,11 @@ just-deploy: ## Deploy the Coherence Operator without rebuilding anything
$(KUSTOMIZE) build $(BUILD_DEPLOY)/default | kubectl apply -f -

.PHONY: prepare-deploy
prepare-deploy: $(BUILD_TARGETS)/manifests $(BUILD_TARGETS)/build-operator kustomize
prepare-deploy: $(BUILD_TARGETS)/manifests $(BUILD_TARGETS)/build-operator $(TOOLS_BIN)/kustomize
$(call prepare_deploy,$(OPERATOR_IMAGE),$(OPERATOR_NAMESPACE))

.PHONY: deploy-debug
deploy-debug: prepare-deploy-debug create-namespace kustomize ## Deploy the Coherence Operator running with Delve
deploy-debug: prepare-deploy-debug create-namespace $(TOOLS_BIN)/kustomize ## Deploy the Coherence Operator running with Delve
ifneq (,$(WATCH_NAMESPACE))
cd $(BUILD_DEPLOY)/manager && $(KUSTOMIZE) edit add configmap env-vars --from-literal WATCH_NAMESPACE=$(WATCH_NAMESPACE)
endif
Expand Down Expand Up @@ -1356,7 +1361,7 @@ port-forward-debug: ## Run a port-forward process to forward localhost:2345 to
kubectl -n $(OPERATOR_NAMESPACE) port-forward $(POD) 2345:2345 || true

.PHONY: prepare-deploy-debug
prepare-deploy-debug: $(BUILD_TARGETS)/manifests build-operator-debug kustomize
prepare-deploy-debug: $(BUILD_TARGETS)/manifests build-operator-debug $(TOOLS_BIN)/kustomize
$(call prepare_deploy,$(OPERATOR_IMAGE_DEBUG),$(OPERATOR_NAMESPACE))

.PHONY: wait-for-deploy
Expand Down Expand Up @@ -1387,7 +1392,7 @@ endef
# Un-deploy controller from the configured Kubernetes cluster in ~/.kube/config
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: undeploy
undeploy: $(BUILD_PROPS) $(BUILD_TARGETS)/manifests kustomize ## Undeploy the Coherence Operator
undeploy: $(BUILD_PROPS) $(BUILD_TARGETS)/manifests $(TOOLS_BIN)/kustomize ## Undeploy the Coherence Operator
@echo "Undeploy Coherence Operator..."
$(call prepare_deploy,$(OPERATOR_IMAGE),$(OPERATOR_NAMESPACE))
$(KUSTOMIZE) build $(BUILD_DEPLOY)/default | kubectl delete -f - || true
Expand All @@ -1406,7 +1411,7 @@ tail-logs: ## Tail the Coherence Operator Pod logs (with follow)
kubectl -n $(OPERATOR_NAMESPACE) logs $(POD) -c manager -f


$(BUILD_MANIFESTS_PKG): kustomize
$(BUILD_MANIFESTS_PKG): $(TOOLS_BIN)/kustomize
rm -rf $(BUILD_MANIFESTS) || true
mkdir -p $(BUILD_MANIFESTS)/crd
$(KUSTOMIZE) build config/crd > $(BUILD_MANIFESTS)/crd/coherence.oracle.com_coherence.yaml
Expand Down Expand Up @@ -1728,7 +1733,7 @@ tanzu-delete-cluster: ## Delete the local Tanzu unmanaged cluster named "$(KIND_
$(TANZU) uc delete $(KIND_CLUSTER)

.PHONY: tanzu-package-internal
tanzu-package-internal: $(BUILD_PROPS) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests kustomize
tanzu-package-internal: $(BUILD_PROPS) $(BUILD_TARGETS)/generate $(BUILD_TARGETS)/manifests $(TOOLS_BIN)/kustomize
rm -r $(TANZU_PACKAGE_DIR) || true
mkdir -p $(TANZU_PACKAGE_DIR)/config $(TANZU_PACKAGE_DIR)/.imgpkg || true
cp -vR tanzu/package/* $(TANZU_PACKAGE_DIR)/config/
Expand Down Expand Up @@ -1826,7 +1831,9 @@ endif
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: controller-gen
CONTROLLER_GEN = $(TOOLS_BIN)/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
controller-gen: $(TOOLS_BIN)/controller-gen ## Download controller-gen locally if necessary.

$(TOOLS_BIN)/controller-gen:
@echo "Downloading controller-gen"
test -s $(TOOLS_BIN)/controller-gen || GOBIN=$(TOOLS_BIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.10.0
ls -al $(TOOLS_BIN)
Expand All @@ -1839,14 +1846,19 @@ KUSTOMIZE_VERSION ?= v3.8.7

.PHONY: kustomize
KUSTOMIZE = $(TOOLS_BIN)/kustomize
kustomize: ## Download kustomize locally if necessary.
kustomize: $(TOOLS_BIN)/kustomize ## Download kustomize locally if necessary.

$(TOOLS_BIN)/kustomize:
test -s $(TOOLS_BIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) --header $(GH_AUTH) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(TOOLS_BIN); }

# ----------------------------------------------------------------------------------------------------------------------
# find or download the Coherence CLI
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: coherence-cli
coherence-cli: $(BUILD_BIN_AMD64)/cohctl $(BUILD_BIN_ARM64)/cohctl ## Download the Coherence CLI locally if necessary.
coherence-cli: $(BUILD_TARGETS)/cli ## Download the Coherence CLI locally if necessary.

$(BUILD_TARGETS)/cli: $(BUILD_BIN_AMD64)/cohctl $(BUILD_BIN_ARM64)/cohctl
touch $(BUILD_TARGETS)/cli

$(BUILD_BIN_AMD64)/cohctl: export COHCTL_HOME=$(BUILD_BIN_AMD64)
$(BUILD_BIN_AMD64)/cohctl: export OS=Linux
Expand Down Expand Up @@ -1948,7 +1960,7 @@ push-ttl-test-images:
# Build the Operator Test images
# ----------------------------------------------------------------------------------------------------------------------
.PHONY: build-compatibility-image
build-compatibility-image: build-mvn
build-compatibility-image: $(BUILD_TARGETS)/java
./mvnw -B -f java/operator-compatibility package -DskipTests \
-Dcoherence.compatibility.image.name=$(TEST_COMPATIBILITY_IMAGE) \
-Dcoherence.compatibility.coherence.image=$(COHERENCE_IMAGE) $(MAVEN_BUILD_OPTS)
Expand Down Expand Up @@ -2105,7 +2117,7 @@ install-istio: get-istio ## Install the latest version of Istio into k8s (or ove
.PHONY: uninstall-istio
uninstall-istio: get-istio ## Uninstall Istio from k8s
$(eval ISTIO_HOME := $(shell find $(TOOLS_DIRECTORY) -maxdepth 1 -type d | grep istio))
$(ISTIO_HOME)/bin/istioctl x uninstall --purge -y
$(ISTIO_HOME)/bin/istioctl uninstall --purge -y


# ----------------------------------------------------------------------------------------------------------------------
Expand Down
39 changes: 25 additions & 14 deletions api/v1/coherence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -78,7 +79,7 @@ func SetCommonDefaults(in CoherenceResource) {

// set the default Coherence local port and local port adjust if not present
if spec.Coherence == nil {
lpa := intstr.FromInt(int(DefaultUnicastPortAdjust))
var lpa = intstr.FromInt32(DefaultUnicastPortAdjust)
spec.Coherence = &CoherenceSpec{
LocalPort: pointer.Int32(DefaultUnicastPort),
LocalPortAdjust: &lpa,
Expand All @@ -88,7 +89,7 @@ func SetCommonDefaults(in CoherenceResource) {
spec.Coherence.LocalPort = pointer.Int32(DefaultUnicastPort)
}
if spec.Coherence.LocalPortAdjust == nil {
lpa := intstr.FromInt(int(DefaultUnicastPortAdjust))
lpa := intstr.FromInt32(DefaultUnicastPortAdjust)
spec.Coherence.LocalPortAdjust = &lpa
}
}
Expand Down Expand Up @@ -128,33 +129,41 @@ var _ webhook.Validator = &Coherence{}
var commonWebHook = CommonWebHook{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (in *Coherence) ValidateCreate() error {
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
func (in *Coherence) ValidateCreate() (admission.Warnings, error) {
var err error
var warnings admission.Warnings

webhookLogger.Info("validate create", "name", in.Name)
err = commonWebHook.validateReplicas(in)
if err != nil {
return err
return warnings, err
}
err = commonWebHook.validateNodePorts(in)
return err
return warnings, err
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (in *Coherence) ValidateUpdate(previous runtime.Object) error {
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
func (in *Coherence) ValidateUpdate(previous runtime.Object) (admission.Warnings, error) {
webhookLogger.Info("validate update", "name", in.Name)
var warnings admission.Warnings

if err := commonWebHook.validateReplicas(in); err != nil {
return err
return warnings, err
}
prev := previous.(*Coherence)

if err := commonWebHook.validatePersistence(in, prev); err != nil {
return err
return warnings, err
}
if err := in.validateVolumeClaimTemplates(prev); err != nil {
return err
return warnings, err
}
if err := commonWebHook.validateNodePorts(in); err != nil {
return err
return warnings, err
}

var errorList field.ErrorList
Expand All @@ -163,16 +172,18 @@ func (in *Coherence) ValidateUpdate(previous runtime.Object) error {
errorList = ValidateStatefulSetUpdate(&sts, &stsOld)

if len(errorList) > 0 {
return fmt.Errorf("rejecting update as it would have resulted in an invalid StatefulSet: %v", errorList)
return warnings, fmt.Errorf("rejecting update as it would have resulted in an invalid StatefulSet: %v", errorList)
}

return nil
return warnings, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (in *Coherence) ValidateDelete() error {
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
func (in *Coherence) ValidateDelete() (admission.Warnings, error) {
// we do not need to validate deletions
return nil
return nil, nil
}

func (in *Coherence) validateVolumeClaimTemplates(previous *Coherence) error {
Expand Down
Loading

0 comments on commit 26c792f

Please sign in to comment.