Skip to content

Commit

Permalink
Merge branch 'update/dependancy-upgrades' of https://github.com/k8ssa…
Browse files Browse the repository at this point in the history
…ndra/k8ssandra-operator into update/dependancy-upgrades
  • Loading branch information
Miles-Garnsey committed May 21, 2024
2 parents a00f1ef + 6a05eea commit e6a4bd5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ require (
google.golang.org/protobuf v1.31.0
gopkg.in/resty.v1 v1.12.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/api v0.29.2
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.17.2
sigs.k8s.io/controller-runtime v0.17.5
sigs.k8s.io/yaml v1.4.0
)

Expand Down Expand Up @@ -96,8 +96,8 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
sigs.k8s.io/gateway-api v0.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,8 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0/go.mod h1:VHVDI/KrK4fjnV61bE2g3sA7tiETLn8sooImelsCx3Y=
sigs.k8s.io/controller-runtime v0.17.2 h1:FwHwD1CTUemg0pW2otk7/U5/i5m2ymzvOXdbeGOUvw0=
sigs.k8s.io/controller-runtime v0.17.2/go.mod h1:+MngTvIQQQhfXtwfdGw/UOQ/aIaqsYywfCINOtwMO/s=
sigs.k8s.io/controller-runtime v0.17.5 h1:1FI9Lm7NiOOmBsgTV36/s2XrEFXnO2C4sbg/Zme72Rw=
sigs.k8s.io/controller-runtime v0.17.5/go.mod h1:N0jpP5Lo7lMTF9aL56Z/B2oWBJjey6StQM0jRbKQXtY=
sigs.k8s.io/gateway-api v0.5.0 h1:ze+k9fJqvmL8s1t3e4q1ST8RnN+f09dEv+gfacahlAE=
sigs.k8s.io/gateway-api v0.5.0/go.mod h1:x0AP6gugkFV8fC/oTlnOMU0pnmuzIR8LfIPRVUjxSqA=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
Expand Down
28 changes: 13 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -142,22 +141,21 @@ func main() {
},
}

options.Cache = cache.Options{
DefaultNamespaces: map[string]cache.Config{},
}

// Add support for MultiNamespace set in WATCH_NAMESPACE (e.g ns1,ns2)
if watchNamespace != "" {
nsConfig := make(map[string]cache.Config)
if strings.Contains(watchNamespace, ",") {
for _, i := range strings.Split(watchNamespace, ",") {
nsConfig[i] = cache.Config{}
}

} else {
nsConfig[watchNamespace] = cache.Config{}
setupLog.Info("watch namespace configured", "namespace", watchNamespace)
}
options.NewCache = func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
opts.DefaultNamespaces = nsConfig
return cache.New(config, opts)
if strings.Contains(watchNamespace, ",") {
setupLog.Info("manager set up with multiple namespaces", "namespaces", watchNamespace)
// configure cluster-scoped with MultiNamespacedCacheBuilder
namespaces := strings.Split(watchNamespace, ",")
for _, namespace := range namespaces {
options.Cache.DefaultNamespaces[namespace] = cache.Config{}
}
} else if watchNamespace != "" {
setupLog.Info("watch namespace configured", "namespace", watchNamespace)
options.Cache.DefaultNamespaces[watchNamespace] = cache.Config{}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
Expand Down
31 changes: 21 additions & 10 deletions test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,47 +498,58 @@ func (f *Framework) DeleteK8ssandraCluster(ctx context.Context, key client.Objec
if err != nil {
return err
}
return wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(ctx context.Context) (bool, error) {

return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
err := f.Client.Get(ctx, key, kc)
return err != nil && errors.IsNotFound(err), nil
})
}

func (f *Framework) DeleteK8ssandraClusters(namespace string, interval, timeout time.Duration) error {
func (f *Framework) DeleteK8ssandraClusters(namespace string, timeout, interval time.Duration) error {
f.logger.Info("Deleting K8ssandraClusters", "Namespace", namespace)
k8ssandra := &api.K8ssandraCluster{}

if err := f.Client.DeleteAllOf(context.TODO(), k8ssandra, client.InNamespace(namespace)); err != nil {
// We set the context here so that it correctly fails the DeleteAllOf operation if the context has timed out
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

if err := f.Client.DeleteAllOf(ctx, k8ssandra, client.InNamespace(namespace)); err != nil {
f.logger.Error(err, "Failed to delete K8ssandraClusters")
return err
}

return wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(ctx context.Context) (bool, error) {
return wait.PollUntilContextCancel(ctx, interval, true, func(ctx context.Context) (bool, error) {
list := &api.K8ssandraClusterList{}
err := f.Client.List(context.Background(), list, client.InNamespace(namespace))
if err != nil {
if err := context.Cause(ctx); err != nil {
f.logger.Error(err, "Failed to delete K8ssandraClusters since context is cancelled in loop")
}
if err := f.Client.List(ctx, list, client.InNamespace(namespace)); err != nil {
f.logger.Info("Waiting for k8ssandracluster deletion", "error", err)
return false, nil
}
f.logger.Info("Waiting for K8ssandraClusters to be deleted", "Namespace", namespace, "Count", len(list.Items))
return len(list.Items) == 0, nil
})
}

func (f *Framework) DeleteCassandraDatacenters(namespace string, interval, timeout time.Duration) error {
func (f *Framework) DeleteCassandraDatacenters(namespace string, timeout, interval time.Duration) error {
f.logger.Info("Deleting CassandraDatacenters", "Namespace", namespace)
dc := &cassdcapi.CassandraDatacenter{}

if err := f.Client.DeleteAllOf(context.Background(), dc, client.InNamespace(namespace)); err != nil {
ctx := context.Background()

if err := f.Client.DeleteAllOf(ctx, dc, client.InNamespace(namespace)); err != nil {
f.logger.Error(err, "Failed to delete CassandraDatacenters")
}

return wait.PollUntilContextTimeout(context.Background(), interval, timeout, true, func(ctx context.Context) (bool, error) {
return wait.PollUntilContextTimeout(ctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
list := &cassdcapi.CassandraDatacenterList{}
err := f.Client.List(context.Background(), list, client.InNamespace(namespace))
err := f.Client.List(ctx, list, client.InNamespace(namespace))
if err != nil {
f.logger.Info("Waiting for CassandraDatacenter deletion", "error", err)
return false, nil
}
f.logger.Info("Waiting for CassandraDatacenters to be deleted", "Namespace", namespace, "Count", len(list.Items))
return len(list.Items) == 0, nil
})
}
Expand Down

0 comments on commit e6a4bd5

Please sign in to comment.