Skip to content

Commit

Permalink
Migrate reaper_controller to k8ssandra-operator (fixes #4) (k8ssandra…
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra authored Nov 23, 2021
1 parent cf0395d commit 1dc67e4
Show file tree
Hide file tree
Showing 72 changed files with 11,491 additions and 2,996 deletions.
1 change: 1 addition & 0 deletions .github/workflows/kind_e2e_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
e2e_test:
- CreateSingleDatacenterCluster
- CreateStargateAndDatacenter
- CreateSingleReaper
fail-fast: false
name: ${{ matrix.e2e_test }}
env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ When cutting a new release, update the `unreleased` heading to the tag being gen
## Unreleased

* [CHANGE] [#182](https://github.com/k8ssandra/k8ssandra-operator/pull/182) Update cass-operator to v1.8.0
* [FEATURE] [#4](https://github.com/k8ssandra/k8ssandra-operator/issues/4) Add support for Reaper
* [FEATURE] [#15](https://github.com/k8ssandra/k8ssandra-operator/pull/15) Add finalizer for K8ssandraCluster
* [BUGFIX] [#203](https://github.com/k8ssandra/k8ssandra-operator/issues/203) Superuser secret name not set on CassandraDatacenters
* [BUGFIX] [#156](https://github.com/k8ssandra/k8ssandra-operator/issues/156) Stargate auth table creation may trigger a table ID mismatch
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ kind-load-image:
kind-e2e-test: multi-up e2e-test

single-up: cleanup build manifests kustomize docker-build create-kind-cluster kind-load-image cert-manager
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply --server-side --force-conflicts -f -

single-reload: build manifests kustomize docker-build kind-load-image cert-manager
kubectl config use-context kind-k8ssandra-0
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply --server-side --force-conflicts -f -
kubectl delete pod -l control-plane=k8ssandra-operator
kubectl rollout status deployment k8ssandra-operator

multi-up: cleanup build manifests kustomize docker-build create-kind-multicluster kind-load-image-multi cert-manager-multi
## install the control plane
kubectl config use-context kind-k8ssandra-0
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply --server-side --force-conflicts -f -
## install the data plane
kubectl config use-context kind-k8ssandra-1
$(KUSTOMIZE) build config/deployments/data-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/data-plane | kubectl apply --server-side --force-conflicts -f -
## Create a client config
make create-client-config
## Restart the control plane
Expand All @@ -172,12 +172,12 @@ multi-up: cleanup build manifests kustomize docker-build create-kind-multicluste
multi-reload: build manifests kustomize docker-build kind-load-image-multi cert-manager-multi
# Reload the operator on the control-plane
kubectl config use-context kind-k8ssandra-0
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply --server-side --force-conflicts -f -
kubectl -n $(NS) delete pod -l control-plane=k8ssandra-operator
kubectl -n $(NS) rollout status deployment k8ssandra-operator
# Reload the operator on the data-plane
kubectl config use-context kind-k8ssandra-1
$(KUSTOMIZE) build config/deployments/data-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/data-plane | kubectl apply --server-side --force-conflicts -f -
kubectl -n $(NS) delete pod -l control-plane=k8ssandra-operator
kubectl -n $(NS) rollout status deployment k8ssandra-operator

Expand Down Expand Up @@ -206,14 +206,14 @@ kind-load-image-multi:
##@ Deployment

install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build config/crd | kubectl apply --server-side --force-conflicts -f -

uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -

deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply -f -
$(KUSTOMIZE) build config/deployments/control-plane | kubectl apply --server-side --force-conflicts -f -

undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/deployments/control-plane | kubectl delete -f -
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ resources:
kind: ReplicatedSecret
path: github.com/k8ssandra/k8ssandra-operator/apis/replication/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: k8ssandra.io
group: reaper
kind: Reaper
path: github.com/k8ssandra/k8ssandra-operator/apis/reaper/v1alpha1
version: v1alpha1
version: "3"
1 change: 1 addition & 0 deletions apis/config/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/k8ssandra/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const (
ComponentLabel = "app.kubernetes.io/component"
ComponentLabelValueCassandra = "cassandra"
ComponentLabelValueStargate = "stargate"
ComponentLabelValueReaper = "reaper"

CreatedByLabel = "app.kubernetes.io/created-by"
CreatedByLabelValueK8ssandraClusterController = "k8ssandracluster-controller"
CreatedByLabelValueStargateController = "stargate-controller"
CreatedByLabelValueReaperController = "reaper-controller"

PartOfLabel = "app.kubernetes.io/part-of"
PartOfLabelValue = "k8ssandra"
Expand Down
42 changes: 36 additions & 6 deletions apis/k8ssandra/v1alpha1/k8ssandracluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
reaperapi "github.com/k8ssandra/k8ssandra-operator/apis/reaper/v1alpha1"
stargateapi "github.com/k8ssandra/k8ssandra-operator/apis/stargate/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -38,6 +39,11 @@ type K8ssandraClusterSpec struct {
// If this is non-nil, Stargate will be deployed on every Cassandra datacenter in this K8ssandraCluster.
// +optional
Stargate *stargateapi.StargateClusterTemplate `json:"stargate,omitempty"`

// Reaper defines the desired deployment characteristics for Reaper in this K8ssandraCluster.
// If this is non-nil, Reaper will be deployed on every Cassandra datacenter in this K8ssandraCluster.
// +optional
Reaper *reaperapi.ReaperClusterTemplate `json:"reaper,omitempty"`
}

// K8ssandraClusterStatus defines the observed state of K8ssandraCluster
Expand All @@ -55,6 +61,7 @@ type K8ssandraClusterStatus struct {
type K8ssandraStatus struct {
Cassandra *cassdcapi.CassandraDatacenterStatus `json:"cassandra,omitempty"`
Stargate *stargateapi.StargateStatus `json:"stargate,omitempty"`
Reaper *reaperapi.ReaperStatus `json:"reaper,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -87,6 +94,24 @@ func (in *K8ssandraCluster) HasStargates() bool {
return false
}

// HasReapers returns true if at least one Reaper resource will be created as part of the creation
// of this K8ssandraCluster object.
func (in *K8ssandraCluster) HasReapers() bool {
if in == nil {
return false
} else if in.Spec.Reaper != nil {
return true
} else if in.Spec.Cassandra == nil || len(in.Spec.Cassandra.Datacenters) == 0 {
return false
}
for _, dcTemplate := range in.Spec.Cassandra.Datacenters {
if dcTemplate.Reaper != nil {
return true
}
}
return false
}

// +kubebuilder:object:root=true

// K8ssandraClusterList contains a list of K8ssandraCluster
Expand Down Expand Up @@ -197,6 +222,11 @@ type CassandraDatacenterTemplate struct {
// deploying Stargate in this datacenter.
// +optional
Stargate *stargateapi.StargateDatacenterTemplate `json:"stargate,omitempty"`

// Reaper defines the desired deployment characteristics for Reaper in this datacenter. Leave nil to skip
// deploying Reaper in this datacenter.
// +optional
Reaper *reaperapi.ReaperDatacenterTemplate `json:"reaper,omitempty"`
}

type EmbeddedObjectMeta struct {
Expand Down Expand Up @@ -236,17 +266,17 @@ type Auth struct {
}

type CassandraYaml struct {
//Authenticator string `json:"authenticator,omitempty"`
// Authenticator string `json:"authenticator,omitempty"`
//
//Authorizer string `json:"authorizer,omitempty"`
// Authorizer string `json:"authorizer,omitempty"`
//
//RoleManager string `json:"role_manager,omitempty"`
// RoleManager string `json:"role_manager,omitempty"`
//
//RoleValidityMillis *int64 `json:"roles_validity_in_ms,omitempty"`
// RoleValidityMillis *int64 `json:"roles_validity_in_ms,omitempty"`
//
//RoleUpdateIntervalMillis *int64 `json:"roles_update_interval_in_ms,omitempty"`
// RoleUpdateIntervalMillis *int64 `json:"roles_update_interval_in_ms,omitempty"`
//
//PermissionValidityMillis *int64 `json:"permissions_validity_in_ms,omitempty"`
// PermissionValidityMillis *int64 `json:"permissions_validity_in_ms,omitempty"`

// +optional
NumTokens *int `json:"num_tokens,omitempty"`
Expand Down
45 changes: 45 additions & 0 deletions apis/k8ssandra/v1alpha1/k8ssandracluster_types_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
reaperapi "github.com/k8ssandra/k8ssandra-operator/apis/reaper/v1alpha1"
"testing"

stargateapi "github.com/k8ssandra/k8ssandra-operator/apis/stargate/v1alpha1"
Expand All @@ -9,6 +10,7 @@ import (

func TestK8ssandraCluster(t *testing.T) {
t.Run("HasStargates", testK8ssandraClusterHasStargates)
t.Run("HasReapers", testK8ssandraClusterHasReapers)
}

func testK8ssandraClusterHasStargates(t *testing.T) {
Expand Down Expand Up @@ -55,3 +57,46 @@ func testK8ssandraClusterHasStargates(t *testing.T) {
assert.True(t, kc.HasStargates())
})
}

func testK8ssandraClusterHasReapers(t *testing.T) {
t.Run("nil receiver", func(t *testing.T) {
var kc *K8ssandraCluster = nil
assert.False(t, kc.HasReapers())
})
t.Run("no reapers", func(t *testing.T) {
kc := K8ssandraCluster{}
assert.False(t, kc.HasReapers())
})
t.Run("cluster-level reaper", func(t *testing.T) {
kc := K8ssandraCluster{
Spec: K8ssandraClusterSpec{
Reaper: &reaperapi.ReaperClusterTemplate{
Keyspace: "reaper",
},
},
}
assert.True(t, kc.HasReapers())
})
t.Run("dc-level reaper", func(t *testing.T) {
kc := K8ssandraCluster{
Spec: K8ssandraClusterSpec{
Cassandra: &CassandraClusterTemplate{
Cluster: "cluster1",
Datacenters: []CassandraDatacenterTemplate{
{
Size: 3,
Reaper: nil,
},
{
Size: 3,
Reaper: &reaperapi.ReaperDatacenterTemplate{
ServiceAccountName: "reaper_sa",
},
},
},
},
},
}
assert.True(t, kc.HasReapers())
})
}
17 changes: 17 additions & 0 deletions apis/k8ssandra/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions apis/reaper/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the reaper v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=reaper.k8ssandra.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "reaper.k8ssandra.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Loading

0 comments on commit 1dc67e4

Please sign in to comment.