Skip to content

Commit

Permalink
Change /etc/reaper to /etc/cassandra-reaper (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbanks authored Nov 12, 2021
1 parent d01d2b7 commit 2a746e6
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ tags

# forks for running tests with custom images
test/config/deploy_reaper_test/overlays/forks/

kind-logs*/
build/

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ ORG?=k8ssandra
PROJECT=reaper-operator
REG?=docker.io

# Change from default of 'kind' as needed
KIND_CLUSTER_NAME=kind

BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
REV=$(shell git rev-parse --short=8 HEAD)

Expand Down Expand Up @@ -121,7 +124,7 @@ docker-push:
docker push ${LATEST_IMAGE}

kind-load-image:
kind load docker-image ${LATEST_IMAGE}
kind load docker-image ${LATEST_IMAGE} --name ${KIND_CLUSTER_NAME}

# find or download controller-gen
# download controller-gen if necessary
Expand Down
5 changes: 4 additions & 1 deletion api/v1alpha1/reaper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ type ReaperSpec struct {
// Tolerations applied to the Reaper pods
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// InitContainerConfig encapsulates configs applied to the Reaper init container
// SchemaInitContainerConfig encapsulates settings applied to the Reaper schema init container
SchemaInitContainerConfig InitContainerConfig `json:"schemaInitContainerConfig,omitempty" yaml:"schemaInitContainerConfig,omitempty"`

// ConfigInitContainerConfig encapsulates settings applied to the Reaper config init container
ConfigInitContainerConfig InitContainerConfig `json:"configInitContainerConfig,omitempty" yaml:"configInitContainerConfig,omitempty"`

// SecurityContext applied to the Reaper non-init container
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

90 changes: 89 additions & 1 deletion config/crd/bases/reaper.cassandra-reaper.io_reapers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,94 @@ spec:
type: array
type: object
type: object
configInitContainerConfig:
description: ConfigInitContainerConfig encapsulates settings applied to the Reaper config init container
properties:
securityContext:
description: SecurityContext applied to a Reaper init container
properties:
allowPrivilegeEscalation:
description: 'AllowPrivilegeEscalation controls whether a process can gain more privileges than its parent process. This bool directly controls if the no_new_privs flag will be set on the container process. AllowPrivilegeEscalation is true always when the container is: 1) run as Privileged 2) has CAP_SYS_ADMIN'
type: boolean
capabilities:
description: The capabilities to add/drop when running containers. Defaults to the default set of capabilities granted by the container runtime.
properties:
add:
description: Added capabilities
items:
description: Capability represent POSIX capabilities type
type: string
type: array
drop:
description: Removed capabilities
items:
description: Capability represent POSIX capabilities type
type: string
type: array
type: object
privileged:
description: Run container in privileged mode. Processes in privileged containers are essentially equivalent to root on the host. Defaults to false.
type: boolean
procMount:
description: procMount denotes the type of proc mount to use for the containers. The default is DefaultProcMount which uses the container runtime defaults for readonly paths and masked paths. This requires the ProcMountType feature flag to be enabled.
type: string
readOnlyRootFilesystem:
description: Whether this container has a read-only root filesystem. Default is false.
type: boolean
runAsGroup:
description: The GID to run the entrypoint of the container process. Uses runtime default if unset. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.
format: int64
type: integer
runAsNonRoot:
description: Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.
type: boolean
runAsUser:
description: The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.
format: int64
type: integer
seLinuxOptions:
description: The SELinux context to be applied to the container. If unspecified, the container runtime will allocate a random SELinux context for each container. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.
properties:
level:
description: Level is SELinux level label that applies to the container.
type: string
role:
description: Role is a SELinux role label that applies to the container.
type: string
type:
description: Type is a SELinux type label that applies to the container.
type: string
user:
description: User is a SELinux user label that applies to the container.
type: string
type: object
seccompProfile:
description: The seccomp options to use by this container. If seccomp options are provided at both the pod & container level, the container options override the pod options.
properties:
localhostProfile:
description: localhostProfile indicates a profile defined in a file on the node should be used. The profile must be preconfigured on the node to work. Must be a descending path, relative to the kubelet's configured seccomp profile location. Must only be set if type is "Localhost".
type: string
type:
description: "type indicates which kind of seccomp profile will be applied. Valid options are: \n Localhost - a profile defined in a file on the node should be used. RuntimeDefault - the container runtime default profile should be used. Unconfined - no profile should be applied."
type: string
required:
- type
type: object
windowsOptions:
description: The Windows specific settings applied to all containers. If unspecified, the options from the PodSecurityContext will be used. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.
properties:
gmsaCredentialSpec:
description: GMSACredentialSpec is where the GMSA admission webhook (https://github.com/kubernetes-sigs/windows-gmsa) inlines the contents of the GMSA credential spec named by the GMSACredentialSpecName field.
type: string
gmsaCredentialSpecName:
description: GMSACredentialSpecName is the name of the GMSA credential spec to use.
type: string
runAsUserName:
description: The UserName in Windows to run the entrypoint of the container process. Defaults to the user specified in image metadata if unspecified. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence.
type: string
type: object
type: object
type: object
image:
type: string
imagePullPolicy:
Expand Down Expand Up @@ -465,7 +553,7 @@ spec:
type: object
type: object
schemaInitContainerConfig:
description: InitContainerConfig encapsulates configs applied to the Reaper init container
description: SchemaInitContainerConfig encapsulates settings applied to the Reaper schema init container
properties:
securityContext:
description: SecurityContext applied to a Reaper init container
Expand Down
11 changes: 11 additions & 0 deletions controllers/reaper_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ var _ = Describe("Reaper controller", func() {
Expect(envVars[len(envVars)-2].ValueFrom.SecretKeyRef.Key).To(Equal("password"))
Expect(envVars[len(envVars)-1].Name).To(Equal("REAPER_CASS_AUTH_ENABLED"))
Expect(envVars[len(envVars)-1].Value).To(Equal("true"))

// Schema init env var check, note: config init doesn't currently utilize these vars
schemaInitEnvVars := deployment.Spec.Template.Spec.InitContainers[1].Env
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-3].Name).To(Equal("REAPER_CASS_AUTH_USERNAME"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-3].ValueFrom.SecretKeyRef.LocalObjectReference.Name).To(Equal("top-secret-cass"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-3].ValueFrom.SecretKeyRef.Key).To(Equal("username"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-2].Name).To(Equal("REAPER_CASS_AUTH_PASSWORD"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-2].ValueFrom.SecretKeyRef.LocalObjectReference.Name).To(Equal("top-secret-cass"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-2].ValueFrom.SecretKeyRef.Key).To(Equal("password"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-1].Name).To(Equal("REAPER_CASS_AUTH_ENABLED"))
Expect(schemaInitEnvVars[len(schemaInitEnvVars)-1].Value).To(Equal("true"))
})
})

Expand Down
45 changes: 41 additions & 4 deletions pkg/reconcile/reconcilers.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func (r *defaultReconciler) ReconcileDeployment(ctx context.Context, req ReaperR
deployment.Spec.RevisionHistoryLimit = desiredDeployment.Spec.RevisionHistoryLimit
deployment.Spec.Strategy = desiredDeployment.Spec.Strategy

deployment.Spec.Template.Spec.Volumes = desiredDeployment.Spec.Template.Spec.Volumes
deployment.Spec.Template.Spec.Containers[0].VolumeMounts = desiredDeployment.Spec.Template.Spec.Containers[0].VolumeMounts

if err = r.Update(ctx, deployment); err != nil {
req.Logger.Error(err, "failed to update deployment", "deployment", deployment)
}
Expand Down Expand Up @@ -401,13 +404,14 @@ func (r *defaultReconciler) buildNewDeployment(req ReaperRequest) (*appsv1.Deplo
}

func addAuthEnvVars(deployment *appsv1.Deployment, vars ...*corev1.EnvVar) {
initEnvVars := deployment.Spec.Template.Spec.InitContainers[0].Env
schemaInitEnvVars := deployment.Spec.Template.Spec.InitContainers[1].Env
envVars := deployment.Spec.Template.Spec.Containers[0].Env

for _, v := range vars {
initEnvVars = append(initEnvVars, *v)
schemaInitEnvVars = append(schemaInitEnvVars, *v)
envVars = append(envVars, *v)
}
deployment.Spec.Template.Spec.InitContainers[0].Env = initEnvVars
deployment.Spec.Template.Spec.InitContainers[1].Env = schemaInitEnvVars
deployment.Spec.Template.Spec.Containers[0].Env = envVars
}

Expand Down Expand Up @@ -506,7 +510,6 @@ func newDeployment(reaper *api.Reaper, cassDcService string) *appsv1.Deployment
}
}
}

return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: reaper.Namespace,
Expand All @@ -525,20 +528,49 @@ func newDeployment(reaper *api.Reaper, cassDcService string) *appsv1.Deployment
Spec: corev1.PodSpec{
Affinity: reaper.Spec.Affinity,
InitContainers: []corev1.Container{
{
Name: "reaper-config-init",
ImagePullPolicy: corev1.PullPolicy(reaper.Spec.ImagePullPolicy),
Image: reaper.Spec.Image,
SecurityContext: reaper.Spec.ConfigInitContainerConfig.SecurityContext,
Command: []string{"/bin/sh"},
Args: []string{"-c", "cp -r /etc/cassandra-reaper/* /reaper-base-config/"},
VolumeMounts: []corev1.VolumeMount{
{
Name: "reaper-config",
ReadOnly: false,
MountPath: "/reaper-base-config/",
},
},
},
{
Name: "reaper-schema-init",
ImagePullPolicy: corev1.PullPolicy(reaper.Spec.ImagePullPolicy),
Image: reaper.Spec.Image,
SecurityContext: reaper.Spec.SchemaInitContainerConfig.SecurityContext,
Env: envVars,
Args: []string{"schema-migration"},
VolumeMounts: []corev1.VolumeMount{
{
Name: "reaper-config",
ReadOnly: false,
MountPath: "/etc/cassandra-reaper",
},
},
},
},
Containers: []corev1.Container{
{
Name: "reaper",
ImagePullPolicy: corev1.PullPolicy(reaper.Spec.ImagePullPolicy),
Image: reaper.Spec.Image,
VolumeMounts: []corev1.VolumeMount{
{
Name: "reaper-config",
ReadOnly: true,
MountPath: "/etc/cassandra-reaper",
},
},
SecurityContext: reaper.Spec.SecurityContext,
Ports: []corev1.ContainerPort{
{
Expand All @@ -560,6 +592,11 @@ func newDeployment(reaper *api.Reaper, cassDcService string) *appsv1.Deployment
ServiceAccountName: reaper.Spec.ServiceAccountName,
Tolerations: reaper.Spec.Tolerations,
SecurityContext: reaper.Spec.PodSecurityContext,
Volumes: []corev1.Volume{
{
Name: "reaper-config",
},
},
},
},
},
Expand Down
Loading

0 comments on commit 2a746e6

Please sign in to comment.