Skip to content

Commit

Permalink
[282] Upgrade to Kubernetes v1.24 and Operator SDK v1.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yersan committed Oct 23, 2023
1 parent 4c40bb4 commit 35db423
Show file tree
Hide file tree
Showing 2,528 changed files with 263,183 additions and 74,003 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)

# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
# You can enable this value if you would like to use SHA Based Digests
# To enable set flag to true
USE_IMAGE_DIGESTS ?= false
ifeq ($(USE_IMAGE_DIGESTS), true)
BUNDLE_GEN_FLAGS += --use-image-digests
endif

# Image URL to use all building/pushing image targets
IMG ?= quay.io/wildfly/wildfly-operator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.19.2
ENVTEST_K8S_VERSION = 1.24

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -239,7 +247,7 @@ endef
bundle: setup-operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
operator-sdk bundle validate ./bundle

.PHONY: setup-operator-sdk
Expand All @@ -263,7 +271,7 @@ ifeq (,$(shell which opm 2>/dev/null))
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.19.1/$${OS}-$${ARCH}-opm ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
Expand Down
2 changes: 1 addition & 1 deletion build/setup-operator-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -o nounset

if ! [ -e "./operator-sdk" ]; then
echo 'Install operator-sdk' >&2
RELEASE_VERSION=v1.3.2
RELEASE_VERSION=v1.22.0
case "$(uname)" in
Darwin*) file=operator-sdk_darwin_amd64;;
*) file=helm-operator_linux_amd64;;
Expand Down
228 changes: 158 additions & 70 deletions config/crd/bases/wildfly.org_wildflyservers.yaml

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ spec:
spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.11.0
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=10"
- "--v=0"
ports:
- containerPort: 8443
name: https
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
- name: manager
args:
- "--health-probe-bind-address=:8081"
Expand Down
4 changes: 2 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ spec:
periodSeconds: 10
resources:
limits:
cpu: 100m
memory: 30Mi
cpu: 200m
memory: 100Mi
requests:
cpu: 100m
memory: 20Mi
Expand Down
4 changes: 4 additions & 0 deletions config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ spec:
endpoints:
- path: /metrics
port: https
scheme: https
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
control-plane: controller-manager
3 changes: 2 additions & 1 deletion config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
ports:
- name: https
port: 8443
protocol: TCP
targetPort: https
selector:
control-plane: controller-manager
control-plane: controller-manager
10 changes: 5 additions & 5 deletions controllers/transaction_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *WildFlyServerReconciler) checkRecovery(reqLogger logr.Logger, scaleDown
// The pod was already searched for the recovery port, marking that into the annotations
annotations := wfly.MapMerge(
scaleDownPod.GetAnnotations(), map[string]string{markerRecoveryPort: strconv.FormatInt(int64(scaleDownPodRecoveryPort), 10)})
patch := client.MergeFrom(scaleDownPod.DeepCopyObject())
patch := client.MergeFrom(scaleDownPod.DeepCopy())
scaleDownPod.SetAnnotations(annotations)
if err := resources.Patch(w, r.Client, scaleDownPod, patch); err != nil {
return false, "", fmt.Errorf("Failed to update pod annotations, pod name %v, annotations to be set %v, error: %v",
Expand All @@ -91,7 +91,7 @@ func (r *WildFlyServerReconciler) checkRecovery(reqLogger logr.Logger, scaleDown
queriedScaleDownPodRecoveryPortString := scaleDownPod.Annotations[markerRecoveryPort]
queriedScaleDownPodRecoveryPort, err := strconv.Atoi(queriedScaleDownPodRecoveryPortString)
if err != nil {
patch := client.MergeFrom(scaleDownPod.DeepCopyObject())
patch := client.MergeFrom(scaleDownPod.DeepCopy())
delete(scaleDownPod.Annotations, markerRecoveryPort)
if errUpdate := resources.Patch(w, r.Client, scaleDownPod, patch); errUpdate != nil {
reqLogger.Info("Cannot update scaledown pod while resetting the recovery port annotation",
Expand All @@ -107,7 +107,7 @@ func (r *WildFlyServerReconciler) checkRecovery(reqLogger logr.Logger, scaleDown
reqLogger.Info("Executing recovery scan at "+scaleDownPodName, "Pod IP", scaleDownPodIP, "Recovery port", scaleDownPodRecoveryPort)
_, err = wfly.RemoteOps.SocketConnect(scaleDownPodIP, scaleDownPodRecoveryPort, txnRecoveryScanCommand)
if err != nil {
patch := client.MergeFrom(scaleDownPod.DeepCopyObject())
patch := client.MergeFrom(scaleDownPod.DeepCopy())
delete(scaleDownPod.Annotations, markerRecoveryPort)
if errUpdate := r.Client.Patch(context.TODO(), scaleDownPod, patch); errUpdate != nil {
reqLogger.Info("Cannot update scaledown pod while resetting the recovery port annotation",
Expand Down Expand Up @@ -211,7 +211,7 @@ func (r *WildFlyServerReconciler) setupRecoveryPropertiesAndRestart(reqLogger lo
reqLogger.Info("Marking pod as being setup for transaction recovery. Adding annotation "+markerRecoveryPropertiesSetup, "Pod Name", scaleDownPodName)
annotations := wfly.MapMerge(
scaleDownPod.GetAnnotations(), map[string]string{markerRecoveryPropertiesSetup: "true"})
patch := client.MergeFrom(scaleDownPod.DeepCopyObject())
patch := client.MergeFrom(scaleDownPod.DeepCopy())
scaleDownPod.SetAnnotations(annotations)
if err := resources.Patch(w, r.Client, scaleDownPod, patch); err != nil {
return requeueNow, fmt.Errorf("Failed to update pod annotations, pod name %v, annotations to be set %v, error: %v",
Expand All @@ -227,7 +227,7 @@ func (r *WildFlyServerReconciler) setupRecoveryPropertiesAndRestart(reqLogger lo
func (r *WildFlyServerReconciler) updatePodLabel(w *wildflyv1alpha1.WildFlyServer, scaleDownPod *corev1.Pod, labelName, labelValue string) (bool, error) {
updated := false
if scaleDownPod.ObjectMeta.Labels[labelName] != labelValue {
patch := client.MergeFrom(scaleDownPod.DeepCopyObject())
patch := client.MergeFrom(scaleDownPod.DeepCopy())
scaleDownPod.ObjectMeta.Labels[labelName] = labelValue
if err := resources.Patch(w, r.Client, scaleDownPod, patch); err != nil {
return false, fmt.Errorf("Failed to update pod labels for pod %v with label [%s=%s], error: %v",
Expand Down
19 changes: 16 additions & 3 deletions controllers/transaction_recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"context"
"fmt"
"github.com/prometheus/common/log"
testifyAssert "github.com/stretchr/testify/assert"
wildflyv1alpha1 "github.com/wildfly/wildfly-operator/api/v1alpha1"
wildflyutil "github.com/wildfly/wildfly-operator/pkg/util"
Expand Down Expand Up @@ -78,6 +77,7 @@ var (
func setupBeforeScaleDown(t *testing.T, wildflyServer *wildflyv1alpha1.WildFlyServer, expectedReplicaSize int32) {
// Set the logger to development mode for verbose logs.
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
log := ctrl.Log.WithName("setupBeforeScaleDown")
assert = testifyAssert.New(t)

// Objects to track in the fake client.
Expand Down Expand Up @@ -147,6 +147,11 @@ func setupBeforeScaleDown(t *testing.T, wildflyServer *wildflyv1alpha1.WildFlySe
}

func TestRecoveryScaleDownToPodInvestigation(t *testing.T) {
// Set the logger to development mode for verbose logs.
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
log := ctrl.Log.WithName("TestRecoveryScaleDownToPodInvestigation")
assert = testifyAssert.New(t)

wildflyServer := defaultWildflyServerDefinition.DeepCopy()
expectedReplicaSize := int32(1)

Expand Down Expand Up @@ -194,10 +199,15 @@ func TestRecoveryScaleDownToPodInvestigation(t *testing.T) {
}

func TestRecoveryScaleDown(t *testing.T) {
// Set the logger to development mode for verbose logs.
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
log := ctrl.Log.WithName("TestRecoveryScaleDown")
assert = testifyAssert.New(t)

wildflyServer := defaultWildflyServerDefinition.DeepCopy()
setupBeforeScaleDown(t, wildflyServer, 1)

log.Info("WildFly server was reconciled, let's scale it down.", "WildflyServer", wildflyServer)
log.Info("WildFly server was reconciled, let's scale it down.", "wildflyServer", wildflyServer)
wildflyServer.Spec.Replicas = 0
err := cl.Update(context.TODO(), wildflyServer)

Expand Down Expand Up @@ -269,6 +279,7 @@ func TestRecoveryScaleDown(t *testing.T) {
func TestSkipRecoveryScaleDownWhenNoTxnSubsystem(t *testing.T) {
wildflyServer := defaultWildflyServerDefinition.DeepCopy()
setupBeforeScaleDown(t, wildflyServer, 1)
log := ctrl.Log.WithName("TestSkipRecoveryScaleDownWhenNoTxnSubsystem")

log.Info("WildFly server was reconciled, let's scale it down.", "WildflyServer", wildflyServer)
wildflyServer.Spec.Replicas = 0
Expand Down Expand Up @@ -304,6 +315,8 @@ func TestSkipRecoveryScaleDownWhenEmptyDirStorage(t *testing.T) {
wildflyServer.Spec.Storage.EmptyDir = &corev1.EmptyDirVolumeSource{} // define emptydir which refuses the claim to be used
setupBeforeScaleDown(t, wildflyServer, 1)

log := ctrl.Log.WithName("TestSkipRecoveryScaleDownWhenEmptyDirStorage")

log.Info("WildFly server was reconciled, let's scale it down.", "WildflyServer", wildflyServer)
wildflyServer.Spec.Replicas = 0
err := cl.Update(context.TODO(), wildflyServer)
Expand Down Expand Up @@ -369,7 +382,7 @@ func (rops *remoteOpsMock) Execute(pod *corev1.Pod, command string) (string, err
}
rops.ExecuteMockReturn = rops.ExecuteMockReturn[1:] // dequeuing, removal of the first item
}
log.Info("remoteOpsMock.Execute command:'" + command + "', returns: '" + stringToReturn + "'")
ctrl.Log.Info("remoteOpsMock.Execute command:'" + command + "', returns: '" + stringToReturn + "'")
return stringToReturn, nil
}
func (rops remoteOpsMock) SocketConnect(hostname string, port int32, command string) (string, error) {
Expand Down
19 changes: 12 additions & 7 deletions controllers/wildflyserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestWildFlyServerControllerCreatesStatefulSet(t *testing.T) {

func TestEnvUpdate(t *testing.T) {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
log := ctrl.Log.WithName("TestEnvUpdate")
assert := testifyAssert.New(t)

initialEnv := &corev1.EnvVar{
Expand Down Expand Up @@ -178,13 +179,14 @@ func TestEnvUpdate(t *testing.T) {
wildflyServer.Spec.Env[0].Value = "UPDATE"
wildflyServer.SetGeneration(wildflyServer.GetGeneration() + 1)
err = cl.Update(context.TODO(), wildflyServer)
t.Logf("WildFlyServerSpec generation %d", wildflyServer.GetGeneration())
log.Info("WildFlyServerSpec generation", "Generation", wildflyServer.GetGeneration())
require.NoError(t, err)

res, err = r.Reconcile(context.TODO(), req)
require.NoError(t, err)
if !res.Requeue {
t.Error("reconcile did not requeue request as expected")
log.Error(nil, "reconcile did not requeue request as expected")
t.FailNow()
}

// check that the statefulset env has been updated
Expand All @@ -199,19 +201,21 @@ func TestEnvUpdate(t *testing.T) {
wildflyServer.Spec.Env = []corev1.EnvVar{}
wildflyServer.SetGeneration(wildflyServer.GetGeneration() + 1)
err = cl.Update(context.TODO(), wildflyServer)
t.Logf("WildFlyServerSpec generation %d", wildflyServer.GetGeneration())
log.Info("WildFlyServerSpec generation", "Generation", wildflyServer.GetGeneration())
require.NoError(t, err)
res, err = r.Reconcile(context.TODO(), req)
require.NoError(t, err)
if !res.Requeue {
t.Error("reconcile did not requeue request as expected")
log.Error(nil, "reconcile did not requeue request as expected")
t.FailNow()
}
// check that the statefulset env has been removed
err = cl.Get(context.TODO(), req.NamespacedName, statefulSet)
require.NoError(t, err)
for _, env := range statefulSet.Spec.Template.Spec.Containers[0].Env {
if env.Name == "TEST_START" {
t.Error("TEST_START env var must be removed")
log.Error(nil, "TEST_START env var must be removed")
t.FailNow()
}
}

Expand All @@ -225,13 +229,14 @@ func TestEnvUpdate(t *testing.T) {
}
wildflyServer.SetGeneration(wildflyServer.GetGeneration() + 1)
err = cl.Update(context.TODO(), wildflyServer)
t.Logf("WildFlyServerSpec generation %d", wildflyServer.GetGeneration())
log.Info("WildFlyServerSpec generation", "Generation", wildflyServer.GetGeneration())
require.NoError(t, err)

res, err = r.Reconcile(context.TODO(), req)
require.NoError(t, err)
if !res.Requeue {
t.Error("reconcile did not requeue request as expected")
log.Error(nil, "reconcile did not requeue request as expected")
t.FailNow()
}

// check that the statefulset env has been added
Expand Down
Loading

0 comments on commit 35db423

Please sign in to comment.