Skip to content

Commit

Permalink
Add settings to configure reaper HTTP management interface (#1082)
Browse files Browse the repository at this point in the history
* Add settings to configure reaper HTTP management interface.

---------

Co-authored-by: Alexander Dejanovski <[email protected]>
  • Loading branch information
Miles-Garnsey and adejanovski authored Oct 19, 2023
1 parent 16f7b8b commit dc5f807
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 40 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/kind_e2e_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ jobs:
with:
go-version-file: 'go.mod'
cache: true
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
with:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/kind_multicluster_e2e_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ jobs:
with:
go-version-file: 'go.mod'
cache: true
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ jobs:
with:
go-version-file: 'go.mod'
cache: true
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
with:
Expand Down
22 changes: 18 additions & 4 deletions apis/reaper/v1alpha1/reaper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ type ReaperTemplate struct {
SecretsProvider string `json:"secretsProvider,omitempty"`

// The image to use for the Reaper pod main container.
// The default is "thelastpickle/cassandra-reaper:3.3.4".
// The default is "thelastpickle/cassandra-reaper:7162ea3".
// +optional
// +kubebuilder:default={repository:"thelastpickle",name:"cassandra-reaper",tag:"3.3.4"}
// TODO: update with real release version.
// +kubebuilder:default={repository:"thelastpickle",name:"cassandra-reaper",tag:"7162ea3"}
ContainerImage *images.Image `json:"containerImage,omitempty"`

// The image to use for the Reaper pod init container (that performs schema migrations).
// The default is "thelastpickle/cassandra-reaper:3.3.4".
// The default is "thelastpickle/cassandra-reaper:7162ea3".
// +optional
// +kubebuilder:default={repository:"thelastpickle",name:"cassandra-reaper",tag:"3.3.4"}
// TODO: update with real release version.
// +kubebuilder:default={repository:"thelastpickle",name:"cassandra-reaper",tag:"7162ea3"}
InitContainerImage *images.Image `json:"initContainerImage,omitempty"`

// +kubebuilder:default="default"
Expand Down Expand Up @@ -139,6 +141,10 @@ type ReaperTemplate struct {
// labels and annotations for Reaper resources
// +optional
ResourceMeta *meta.ResourceMeta `json:"metadata,omitempty"`

// +kubebuilder:default={enabled: false}
// +optional
HttpManagement HttpManagement `json:"httpManagement"`
}

// UseExternalSecrets defines whether the user has specified if credentials and
Expand Down Expand Up @@ -367,6 +373,14 @@ type Reaper struct {
Status ReaperStatus `json:"status,omitempty"`
}

type HttpManagement struct {
// Enable/disable the HTTP management connection between Reaper and Cassandra.
// When enabled, HTTP will be used instead of JMX for management connectivity between Cassandra
// and Reaper. In future, this will be true by default
// +kubebuilder:default=false
Enabled bool `json:"enabled"`
}

// +kubebuilder:object:root=true

// ReaperList contains a list of Reaper
Expand Down
16 changes: 16 additions & 0 deletions apis/reaper/v1alpha1/zz_generated.deepcopy.go

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

28 changes: 22 additions & 6 deletions config/crd/bases/k8ssandra.io_k8ssandraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28402,9 +28402,10 @@ spec:
default:
name: cassandra-reaper
repository: thelastpickle
tag: 3.3.4
description: The image to use for the Reaper pod main container.
The default is "thelastpickle/cassandra-reaper:3.3.4".
tag: 7162ea3
description: 'The image to use for the Reaper pod main container.
The default is "thelastpickle/cassandra-reaper:7162ea3". TODO:
update with real release version.'
properties:
name:
description: The image name to use.
Expand Down Expand Up @@ -28457,13 +28458,28 @@ spec:
description: HeapSize sets the JVM heap size to use for Reaper.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
httpManagement:
default:
enabled: false
properties:
enabled:
default: false
description: Enable/disable the HTTP management connection
between Reaper and Cassandra. When enabled, HTTP will be
used instead of JMX for management connectivity between
Cassandra and Reaper. In future, this will be true by default
type: boolean
required:
- enabled
type: object
initContainerImage:
default:
name: cassandra-reaper
repository: thelastpickle
tag: 3.3.4
description: The image to use for the Reaper pod init container
(that performs schema migrations). The default is "thelastpickle/cassandra-reaper:3.3.4".
tag: 7162ea3
description: 'The image to use for the Reaper pod init container
(that performs schema migrations). The default is "thelastpickle/cassandra-reaper:7162ea3".
TODO: update with real release version.'
properties:
name:
description: The image name to use.
Expand Down
28 changes: 22 additions & 6 deletions config/crd/bases/reaper.k8ssandra.io_reapers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,10 @@ spec:
default:
name: cassandra-reaper
repository: thelastpickle
tag: 3.3.4
description: The image to use for the Reaper pod main container. The
default is "thelastpickle/cassandra-reaper:3.3.4".
tag: 7162ea3
description: 'The image to use for the Reaper pod main container.
The default is "thelastpickle/cassandra-reaper:7162ea3". TODO: update
with real release version.'
properties:
name:
description: The image name to use.
Expand Down Expand Up @@ -1127,13 +1128,28 @@ spec:
description: HeapSize sets the JVM heap size to use for Reaper.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
httpManagement:
default:
enabled: false
properties:
enabled:
default: false
description: Enable/disable the HTTP management connection between
Reaper and Cassandra. When enabled, HTTP will be used instead
of JMX for management connectivity between Cassandra and Reaper.
In future, this will be true by default
type: boolean
required:
- enabled
type: object
initContainerImage:
default:
name: cassandra-reaper
repository: thelastpickle
tag: 3.3.4
description: The image to use for the Reaper pod init container (that
performs schema migrations). The default is "thelastpickle/cassandra-reaper:3.3.4".
tag: 7162ea3
description: 'The image to use for the Reaper pod init container (that
performs schema migrations). The default is "thelastpickle/cassandra-reaper:7162ea3".
TODO: update with real release version.'
properties:
name:
description: The image name to use.
Expand Down
4 changes: 3 additions & 1 deletion controllers/reaper/reaper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package reaper

import (
"context"
"fmt"

"github.com/go-logr/logr"
cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
Expand Down Expand Up @@ -157,7 +158,7 @@ func (r *ReaperReconciler) reconcileDeployment(

deploymentKey := types.NamespacedName{Namespace: actualReaper.Namespace, Name: actualReaper.Name}
logger = logger.WithValues("Deployment", deploymentKey)
logger.Info("Reconciling Reaper Deployment")
logger.Info(fmt.Sprintf("Reconciling reaper deployment, req was %#v", actualReaper))

authVars, err := r.collectAuthVars(ctx, actualReaper, logger)
if err != nil {
Expand Down Expand Up @@ -190,6 +191,7 @@ func (r *ReaperReconciler) reconcileDeployment(
return vectorReconcileResult, nil
}

logger.Info("Reconciling reaper deployment", "actualReaper", actualReaper)
desiredDeployment := reaper.NewDeployment(actualReaper, actualDc, keystorePassword, truststorePassword, logger, authVars...)

actualDeployment := &appsv1.Deployment{}
Expand Down
8 changes: 7 additions & 1 deletion pkg/reaper/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
DefaultImageRepository = "thelastpickle"
DefaultImageName = "cassandra-reaper"
DefaultVersion = "3.3.4"
DefaultVersion = "7162ea3"
// When changing the default version above, please also change the kubebuilder markers in
// apis/reaper/v1alpha1/reaper_types.go accordingly.

Expand Down Expand Up @@ -152,6 +152,12 @@ func NewDeployment(reaper *api.Reaper, dc *cassdcapi.CassandraDatacenter, keysto
Value: fmt.Sprintf("%d", reaper.Spec.HeapSize.Value()),
})
}
if reaper.Spec.HttpManagement.Enabled {
envVars = append(envVars, corev1.EnvVar{
Name: "REAPER_HTTP_MANAGEMENT_ENABLE",
Value: "true",
})
}

volumeMounts := []corev1.VolumeMount{}
volumes := []corev1.Volume{}
Expand Down
21 changes: 15 additions & 6 deletions pkg/reaper/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestNewDeployment(t *testing.T) {
reaper.Spec.AutoScheduling = reaperapi.AutoScheduling{Enabled: false}
reaper.Spec.ServiceAccountName = "reaper"
reaper.Spec.DatacenterAvailability = DatacenterAvailabilityAll
reaper.Spec.HttpManagement.Enabled = true
reaper.Spec.ClientEncryptionStores = &encryption.Stores{
KeystoreSecretRef: &encryption.SecretKeySelector{LocalObjectReference: corev1.LocalObjectReference{
Name: "keystore-secret",
Expand Down Expand Up @@ -116,6 +117,10 @@ func TestNewDeployment(t *testing.T) {
Name: "REAPER_CASS_NATIVE_PROTOCOL_SSL_ENCRYPTION_ENABLED",
Value: "true",
},
{
Name: "REAPER_HTTP_MANAGEMENT_ENABLE",
Value: "true",
},
})

assert.Len(t, podSpec.InitContainers, 1)
Expand Down Expand Up @@ -156,6 +161,10 @@ func TestNewDeployment(t *testing.T) {
Name: "REAPER_CASS_NATIVE_PROTOCOL_SSL_ENCRYPTION_ENABLED",
Value: "true",
},
{
Name: "REAPER_HTTP_MANAGEMENT_ENABLE",
Value: "true",
},
})

assert.ElementsMatch(t, initContainer.Args, []string{"schema-migration"})
Expand All @@ -177,7 +186,7 @@ func TestNewDeployment(t *testing.T) {
deployment = NewDeployment(reaper, newTestDatacenter(), nil, nil, logger)
podSpec = deployment.Spec.Template.Spec
container = podSpec.Containers[0]
assert.Len(t, container.Env, 6)
assert.Len(t, container.Env, 7)

assert.Contains(t, container.Env, corev1.EnvVar{
Name: "REAPER_CASS_KEYSPACE",
Expand All @@ -188,7 +197,7 @@ func TestNewDeployment(t *testing.T) {
deployment = NewDeployment(reaper, newTestDatacenter(), nil, nil, logger)
podSpec = deployment.Spec.Template.Spec
container = podSpec.Containers[0]
assert.Len(t, container.Env, 16)
assert.Len(t, container.Env, 17)

assert.Contains(t, container.Env, corev1.EnvVar{
Name: "REAPER_AUTO_SCHEDULING_ADAPTIVE",
Expand Down Expand Up @@ -302,8 +311,8 @@ func TestImages(t *testing.T) {
reaper.Spec.ContainerImage = nil
logger := testlogr.NewTestLogger(t)
deployment := NewDeployment(reaper, newTestDatacenter(), nil, nil, logger)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:3.3.4", deployment.Spec.Template.Spec.InitContainers[0].Image)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:3.3.4", deployment.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:7162ea3", deployment.Spec.Template.Spec.InitContainers[0].Image)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:7162ea3", deployment.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, corev1.PullIfNotPresent, deployment.Spec.Template.Spec.InitContainers[0].ImagePullPolicy)
assert.Equal(t, corev1.PullIfNotPresent, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy)
assert.Empty(t, deployment.Spec.Template.Spec.ImagePullSecrets)
Expand All @@ -318,8 +327,8 @@ func TestImages(t *testing.T) {
reaper.Spec.ContainerImage = nil
logger := testlogr.NewTestLogger(t)
deployment := NewDeployment(reaper, newTestDatacenter(), nil, nil, logger)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:3.3.4", deployment.Spec.Template.Spec.InitContainers[0].Image)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:3.3.4", deployment.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:7162ea3", deployment.Spec.Template.Spec.InitContainers[0].Image)
assert.Equal(t, "docker.io/thelastpickle/cassandra-reaper:7162ea3", deployment.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, corev1.PullIfNotPresent, deployment.Spec.Template.Spec.InitContainers[0].ImagePullPolicy)
assert.Equal(t, corev1.PullIfNotPresent, deployment.Spec.Template.Spec.Containers[0].ImagePullPolicy)
assert.Empty(t, deployment.Spec.Template.Spec.ImagePullSecrets)
Expand Down
12 changes: 10 additions & 2 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,10 @@ func TestOperator(t *testing.T) {
fixture: framework.NewTestFixture("multi-dc-stargate", controlPlane),
}))
t.Run("CreateSingleReaper", e2eTest(ctx, &e2eTestOpts{
testFunc: createSingleReaper,
fixture: framework.NewTestFixture("single-dc-reaper", controlPlane),
testFunc: createSingleReaper,
fixture: framework.NewTestFixture("single-dc-reaper", controlPlane),
skipK8ssandraClusterCleanup: false,
doCassandraDatacenterCleanup: true,
}))
t.Run("CreateMultiReaper", e2eTest(ctx, &e2eTestOpts{
testFunc: createMultiReaper,
Expand All @@ -260,6 +262,12 @@ func TestOperator(t *testing.T) {
skipK8ssandraClusterCleanup: true,
doCassandraDatacenterCleanup: true,
}))
t.Run("CreateReaperHttpManagement", e2eTest(ctx, &e2eTestOpts{
testFunc: createReaperAndDatacenter, // same as above, ensure we can trigger repair. Only difference is that we use a fixture which enabled the HTTP management interface.
fixture: framework.NewTestFixture("reaper-http-management", dataPlanes[0]),
skipK8ssandraClusterCleanup: true,
doCassandraDatacenterCleanup: true,
}))
t.Run("ClusterScoped", func(t *testing.T) {
t.Run("MultiDcMultiCluster", e2eTest(ctx, &e2eTestOpts{
testFunc: multiDcMultiCluster,
Expand Down
4 changes: 2 additions & 2 deletions test/kuttl/test-servicemonitors/02-prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
kustomize build ./config/prometheus | kubectl apply --server-side -f -
kustomize build ./config/prometheus | kubectl apply --server-side --force-conflicts -f -
ignoreFailure: true
- script: |
until kubectl get crd servicemonitors.monitoring.coreos.com; do sleep 5; done
Expand All @@ -11,5 +11,5 @@ commands:
until kubectl get crd prometheuses.monitoring.coreos.com; do sleep 5; done
ignoreFailure: true
- script: |
kustomize build ./config/prometheus | kubectl apply --server-side -f -
kustomize build ./config/prometheus | kubectl apply --server-side --force-conflicts -f -
ignoreFailure: false
Loading

0 comments on commit dc5f807

Please sign in to comment.