Skip to content

Commit

Permalink
Merge pull request cscetbon#126 from AKamyshnikova/k8s-libs-27.5
Browse files Browse the repository at this point in the history
K8s libs 27.5
  • Loading branch information
AKamyshnikova authored Sep 15, 2023
2 parents d645271 + 28c6701 commit 739e3e2
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 1,194 deletions.
125 changes: 110 additions & 15 deletions charts/casskop/crds/db.orange.com_cassandraclusters.yaml

Large diffs are not rendered by default.

125 changes: 110 additions & 15 deletions charts/multi-casskop/crds/db.orange.com_cassandraclusters.yaml

Large diffs are not rendered by default.

125 changes: 110 additions & 15 deletions config/crd/bases/db.orange.com_cassandraclusters.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion controllers/cassandrabackup/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func HelperInitCassandraBackupController(cassandraBackupYaml string) (*Cassandra
&cassandraBackup,
}

fakeClient := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).WithStatusSubresource(&cassandraBackup).Build()

fakeRecorder := record.NewFakeRecorder(3)
reconcileCassandraBackup := CassandraBackupReconciler{
Expand Down
42 changes: 23 additions & 19 deletions controllers/cassandracluster/cassandra_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//Global var used to know if we need to update the CRD
// Global var used to know if we need to update the CRD
var needUpdate bool

//updateCassandraStatus updates the CRD if the status has changed
//if needUpdate is set that mean that we have updated some fields in the CRD
//This method also stored the annotation cassandraclusters.db.orange.com/last-applied-configuration with last-applied-configuration
// updateCassandraStatus updates the CRD if the status has changed
// if needUpdate is set that mean that we have updated some fields in the CRD
// This method also stored the annotation cassandraclusters.db.orange.com/last-applied-configuration with last-applied-configuration
func (rcc *CassandraClusterReconciler) updateCassandraStatus(ctx context.Context, cc *api.CassandraCluster,
status *api.CassandraClusterStatus) error {
// don't update the status if there aren't any changes.
Expand All @@ -53,9 +53,13 @@ func (rcc *CassandraClusterReconciler) updateCassandraStatus(ctx context.Context
needUpdate = false
//make also deepcopy to avoid pointer conflict
cc.Status = *status.DeepCopy()
err := rcc.Client.Status().Update(ctx, cc)
if err != nil {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "err": err}).Errorf("Issue when updating CassandraCluster Status")
}
cc.Annotations[api.AnnotationLastApplied] = string(lastApplied)

err := rcc.Client.Update(ctx, cc)
err = rcc.Client.Update(ctx, cc)
if err != nil {
logrus.WithFields(logrus.Fields{"cluster": cc.Name, "err": err}).Errorf("Issue when updating CassandraCluster")
}
Expand Down Expand Up @@ -151,10 +155,10 @@ func (rcc *CassandraClusterReconciler) getNextCassandraClusterStatus(ctx context
return nil
}

//needToWaitDelayBeforeCheck will return if last action start time is < to api.DefaultDelayWait
//that means the last operation was started only a few seconds ago and checking now would not make any sense
//this is mostly to give cassandra and the operator enough time to correctly stage the action
//DefaultDelayWait is of 2 minutes
// needToWaitDelayBeforeCheck will return if last action start time is < to api.DefaultDelayWait
// that means the last operation was started only a few seconds ago and checking now would not make any sense
// this is mostly to give cassandra and the operator enough time to correctly stage the action
// DefaultDelayWait is of 2 minutes
func needToWaitDelayBeforeCheck(cc *api.CassandraCluster, dcRackName string, storedStatefulSet *appsv1.StatefulSet,
status *api.CassandraClusterStatus) bool {
lastAction := &status.CassandraRackStatus[dcRackName].CassandraLastAction
Expand All @@ -166,16 +170,16 @@ func needToWaitDelayBeforeCheck(cc *api.CassandraCluster, dcRackName string, sto
if t.Add(api.DefaultDelayWait * time.Second).After(now.Time) {
logrus.WithFields(logrus.Fields{"cluster": cc.Name,
"rack": dcRackName}).Info(
fmt.Sprintf("The Operator Waits %s seconds for the action to start correctly",
strconv.Itoa(api.DefaultDelayWait)),
)
fmt.Sprintf("The Operator Waits %s seconds for the action to start correctly",
strconv.Itoa(api.DefaultDelayWait)),
)
return true
}
}
return false
}

//UpdateStatusIfconfigMapHasChanged updates CassandraCluster Action Status if it detect a changes :
// UpdateStatusIfconfigMapHasChanged updates CassandraCluster Action Status if it detect a changes :
// - a new configmapName in the CRD
// - or the add or remoove of the configmap in the CRD
func UpdateStatusIfconfigMapHasChanged(cc *api.CassandraCluster, dcRackName string, storedStatefulSet *appsv1.StatefulSet, status *api.CassandraClusterStatus) bool {
Expand Down Expand Up @@ -220,7 +224,7 @@ func UpdateStatusIfconfigMapHasChanged(cc *api.CassandraCluster, dcRackName stri
return false
}

//UpdateStatusIfDockerImageHasChanged updates CassandraCluster Action Status if it detect a changes in the DockerImage:
// UpdateStatusIfDockerImageHasChanged updates CassandraCluster Action Status if it detect a changes in the DockerImage:
func UpdateStatusIfDockerImageHasChanged(cc *api.CassandraCluster, dcRackName string, storedStatefulSet *appsv1.StatefulSet, status *api.CassandraClusterStatus) bool {

desiredDockerImage := cc.Spec.CassandraImage
Expand Down Expand Up @@ -263,7 +267,7 @@ func UpdateStatusIfRollingRestart(cc *api.CassandraCluster, dc,
return false
}

//UpdateStatusIfSeedListHasChanged updates CassandraCluster Action Status if it detects a change
// UpdateStatusIfSeedListHasChanged updates CassandraCluster Action Status if it detects a change
func UpdateStatusIfSeedListHasChanged(cc *api.CassandraCluster, dcRackName string,
storedStatefulSet *appsv1.StatefulSet, status *api.CassandraClusterStatus) bool {

Expand Down Expand Up @@ -298,9 +302,9 @@ func UpdateStatusIfSeedListHasChanged(cc *api.CassandraCluster, dcRackName strin
return false
}

//UpdateStatusIfScaling will detect any change of replicas
//To Scale Down the operator will need to first decommission the last node from Cassandra before removing it from kubernetes.
//To Scale Up some PodOperations may be scheduled if Auto-pilot is activeted.
// UpdateStatusIfScaling will detect any change of replicas
// To Scale Down the operator will need to first decommission the last node from Cassandra before removing it from kubernetes.
// To Scale Up some PodOperations may be scheduled if Auto-pilot is activeted.
func UpdateStatusIfScaling(cc *api.CassandraCluster, dcRackName string, storedStatefulSet *appsv1.StatefulSet,
status *api.CassandraClusterStatus) bool {
nodesPerRacks := cc.GetNodesPerRacks(dcRackName)
Expand Down Expand Up @@ -343,7 +347,7 @@ func UpdateStatusIfStatefulSetChanged(dcRackName string, storedStatefulSet *apps
return false
}

//UpdateStatusIfActionEnded Implement Tests to detect End of Ongoing Actions
// UpdateStatusIfActionEnded Implement Tests to detect End of Ongoing Actions
func (rcc *CassandraClusterReconciler) UpdateStatusIfActionEnded(ctx context.Context, cc *api.CassandraCluster, dcName string,
rackName string, storedStatefulSet *appsv1.StatefulSet, status *api.CassandraClusterStatus) bool {
dcRackName := cc.GetDCRackName(dcName, rackName)
Expand Down
5 changes: 3 additions & 2 deletions controllers/cassandracluster/cassandra_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ func HelperInitCluster(t *testing.T, name string) (*CassandraClusterReconciler,
fakeClientScheme := scheme.Scheme
fakeClientScheme.AddKnownTypes(api.GroupVersion, &cc)
fakeClientScheme.AddKnownTypes(api.GroupVersion, &ccList)
cl := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).WithStatusSubresource(&cc).Build()
// Create a CassandraClusterReconciler object with the scheme and fake client.
rcc := CassandraClusterReconciler{Client: cl, Scheme: fakeClientScheme}

cc.InitCassandraRackList()
cl.Status().Update(context.TODO(), &cc)
return &rcc, &cc
}

Expand Down Expand Up @@ -197,7 +198,7 @@ func helperCreateCassandraCluster(ctx context.Context, t *testing.T, cassandraCl
//Now simulate sts to be ready for CassKop
sts.Status.Replicas = *sts.Spec.Replicas
sts.Status.ReadyReplicas = *sts.Spec.Replicas
rcc.UpdateStatefulSet(ctx, sts)
rcc.Client.Status().Update(ctx, sts)

//Create Statefulsets associated fake Pods
podTemplate := v1.Pod{
Expand Down
4 changes: 2 additions & 2 deletions controllers/cassandracluster/decommission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func createCassandraClusterWithNoDisruption(t *testing.T, cassandraClusterFileNa
rcc.Client.Get(context.TODO(), req.NamespacedName, pdb)
// No disruption
pdb.Status.DisruptionsAllowed = 1
rcc.Client.Update(context.TODO(), pdb)
rcc.Client.Status().Update(context.TODO(), pdb)

return rcc, req
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestOneDecommission(t *testing.T) {
deletePodNotDeletedByFakeClient(rcc, deletedPod)
stfs, _ := rcc.GetStatefulSet(ctx, namespace, stfsName)
stfs.Status.ReadyReplicas = 2
rcc.Client.Update(context.TODO(), stfs)
rcc.Client.Status().Update(context.TODO(), stfs)

registerFatalJolokiaResponder(t, deletedPod)
registerJolokiaOperationModeResponder(lastPod, NORMAL)
Expand Down
2 changes: 1 addition & 1 deletion controllers/cassandracluster/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func helperInitCluster(t *testing.T, name string) (*CassandraClusterReconciler,
fakeClientScheme := scheme.Scheme
fakeClientScheme.AddKnownTypes(api.GroupVersion, &cc)
fakeClientScheme.AddKnownTypes(api.GroupVersion, &ccList)
cl := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).Build()
cl := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).WithStatusSubresource(&cc).Build()
// Create a CassandraClusterReconciler object with the scheme and fake client.
rcc := CassandraClusterReconciler{Client: cl, Scheme: fakeClientScheme}

Expand Down
2 changes: 1 addition & 1 deletion controllers/cassandrarestore/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func helperInitCassandraRestoreController(cassandraRestoreYaml string) (*Cassand
&cassandraRestore,
}

fakeClient := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(fakeClientScheme).WithRuntimeObjects(objs...).WithStatusSubresource(&cassandraRestore).Build()

fakeRecorder := record.NewFakeRecorder(3)
CassandraRestoreReconciler := CassandraRestoreReconciler{
Expand Down
2 changes: 1 addition & 1 deletion docker/casskop/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19 as build
FROM golang:1.20 as build

ARG COMPILED_DATE
ARG VERSION
Expand Down
2 changes: 1 addition & 1 deletion docker/ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19
FROM golang:1.20

# Make Apt non-interactive
RUN echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90ci \
Expand Down
1 change: 0 additions & 1 deletion docker/multi-casskop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN go mod edit -replace github.com/cscetbon/casskop=/workspace
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
RUN go mod vendor

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o multi-casskop main.go
Expand Down
95 changes: 41 additions & 54 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,104 +1,91 @@
module github.com/cscetbon/casskop

go 1.19
go 1.20

require (
emperror.dev/errors v0.8.0
github.com/Jeffail/gabs v1.4.0
github.com/allamand/godebug v0.0.0-20190404121221-3ec752cd7166
github.com/antihax/optional v1.0.0
github.com/banzaicloud/k8s-objectmatcher v1.8.0
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f // indirect
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-logr/logr v1.2.3
github.com/go-logr/logr v1.2.4
github.com/instaclustr/instaclustr-icarus-go-client v0.0.0-20210427160512-5264f1cbba08
github.com/jarcoal/httpmock v1.0.4
github.com/jarcoal/httpmock v1.3.0
github.com/mitchellh/mapstructure v1.4.1
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
github.com/prometheus/client_golang v1.14.0
github.com/operator-framework/operator-lib v0.11.0
github.com/prometheus/client_golang v1.15.1
github.com/r3labs/diff v0.0.0-20190801153147-a71de73c46ad
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.0
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.4
github.com/swarvanusg/go_jolokia v0.0.0-20190213021437-3cd2b3fc4f36
github.com/thoas/go-funk v0.4.0
github.com/zput/zxcTool v1.3.6
golang.org/x/net v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
k8s.io/api v0.25.6
k8s.io/apimachinery v0.25.6
k8s.io/client-go v0.25.6
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
sigs.k8s.io/controller-runtime v0.12.1
go.uber.org/zap v1.24.0
golang.org/x/text v0.9.0
k8s.io/api v0.27.5
k8s.io/apimachinery v0.27.5
k8s.io/client-go v0.27.5
sigs.k8s.io/controller-runtime v0.15.0
)

require (
github.com/operator-framework/operator-lib v0.11.0
go.uber.org/zap v1.19.1
golang.org/x/text v0.8.0
)

require (
cloud.google.com/go v0.97.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/antonfisher/nested-logrus-formatter v1.0.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/goph/emperror v0.17.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.24.0 // indirect
k8s.io/component-base v0.25.6 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.5 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 739e3e2

Please sign in to comment.