Skip to content

Commit

Permalink
Bundle modifications (#567)
Browse files Browse the repository at this point in the history
* Revert 640a4db, remove OSE specific ServiceAccountName from pods

* Add k8ssandra-client from quay.io to certified-bundle

* Fix some rebase issues

* Remove k8ssandra-client from registry.connect.redhat.com for now

* No backport

* One more
  • Loading branch information
burmanm authored Sep 9, 2023
1 parent 3e957ad commit 214035d
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 186 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti

## unreleased

* [CHANGE] [#541](https://github.com/k8ssandra/cass-operator/issues/541) Revert when deployed through OLM, add serviceAccount to Cassandra pods that use nonroot priviledge. This is no longer necessary with 1.17.0 and up.

## v1.17.0

* [CHANGE] [#565](https://github.com/k8ssandra/cass-operator/issues/565) Replace the use of wget with curl when making Kubernetes -> management-api HTTP(S) calls
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ endif
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OPSDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
scripts/preprocess-bundle.sh
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/manifests | $(OPSDK) generate bundle -q --overwrite --extra-service-accounts cass-operator-cassandra-default-sa --version $(VERSION) $(BUNDLE_METADATA_OPTS)
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/manifests | $(OPSDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
scripts/postprocess-bundle.sh $(REGISTRY)
$(OPSDK) bundle validate ./bundle --select-optional suite=operatorframework

Expand Down
3 changes: 0 additions & 3 deletions apis/config/v1beta1/operatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ type OperatorConfig struct {

// ImageConfigFile indicates the path where to load the imageConfig from
ImageConfigFile string `json:"imageConfigFile,omitempty"`

// OLMDeployed is set to true when operator is deployed through OLM. This will activate additional Openshift features
OLMDeployed bool `json:"olmDeployment,omitempty"`
}

func init() {
Expand Down
9 changes: 4 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ func main() {
}

if err = (&controllers.CassandraDatacenterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("CassandraDatacenter"),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("cass-operator"),
OperatorConfig: &operConfig,
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("CassandraDatacenter"),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("cass-operator"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "CassandraDatacenter")
os.Exit(1)
Expand Down
1 change: 0 additions & 1 deletion config/components/webhook/controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ leaderElection:
resourceName: b569adb7.cassandra.datastax.com
disableWebhooks: false
imageConfigFile: /configs/image_config.yaml
olmDeployment: false
1 change: 0 additions & 1 deletion config/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ leaderElection:
resourceName: b569adb7.cassandra.datastax.com
disableWebhooks: true
imageConfigFile: /configs/image_config.yaml
olmDeployment: false
25 changes: 0 additions & 25 deletions config/rbac/nonroot_role.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions config/rbac/service_account_nonroot.yaml

This file was deleted.

1 change: 1 addition & 0 deletions config/samples/example-cassdc-three-nodes-single-rack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spec:
resources:
requests:
storage: 10Gi
dockerImageRunsAsCassandra: false
resources:
requests:
memory: 2Gi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

api "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
configv1beta1 "github.com/k8ssandra/cass-operator/apis/config/v1beta1"
)

var (
Expand Down Expand Up @@ -76,9 +75,6 @@ type CassandraDatacenterReconciler struct {
// during reconciliation where we update the mappings for the watches.
// Putting it here allows us to get it to both places.
SecretWatches dynamicwatch.DynamicWatches

// OperatorConfig allows Reconciler to access generic configuration properties
OperatorConfig *configv1beta1.OperatorConfig
}

// Reconcile reads that state of the cluster for a Datacenter object
Expand Down Expand Up @@ -109,7 +105,7 @@ func (r *CassandraDatacenterReconciler) Reconcile(ctx context.Context, request c

logger.Info("======== handler::Reconcile has been called")

rc, err := reconciliation.CreateReconciliationContext(ctx, &request, r.Client, r.Scheme, r.Recorder, r.SecretWatches, r.OperatorConfig.OLMDeployed)
rc, err := reconciliation.CreateReconciliationContext(ctx, &request, r.Client, r.Scheme, r.Recorder, r.SecretWatches)

if err != nil {
if errors.IsNotFound(err) {
Expand Down
14 changes: 4 additions & 10 deletions internal/controllers/cassandra/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

cassandradatastaxcomv1beta1 "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
configv1beta1 "github.com/k8ssandra/cass-operator/apis/config/v1beta1"
controlapi "github.com/k8ssandra/cass-operator/apis/control/v1alpha1"
"github.com/k8ssandra/cass-operator/pkg/images"
"github.com/k8ssandra/cass-operator/pkg/reconciliation"
Expand Down Expand Up @@ -97,16 +96,11 @@ var _ = BeforeSuite(func() {
})
Expect(err).ToNot(HaveOccurred())

operConfig := &configv1beta1.OperatorConfig{
OLMDeployed: false,
}

err = (&CassandraDatacenterReconciler{
Client: k8sClient,
Log: ctrl.Log.WithName("controllers").WithName("CassandraDatacenter"),
Scheme: k8sManager.GetScheme(),
Recorder: k8sManager.GetEventRecorderFor("cass-operator"),
OperatorConfig: operConfig,
Client: k8sClient,
Log: ctrl.Log.WithName("controllers").WithName("CassandraDatacenter"),
Scheme: k8sManager.GetScheme(),
Recorder: k8sManager.GetEventRecorderFor("cass-operator"),
}).SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

Expand Down
6 changes: 1 addition & 5 deletions pkg/reconciliation/construct_podtemplatespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const (
CassandraContainerName = "cassandra"
PvcName = "server-data"
SystemLoggerContainerName = "server-system-logger"
OpenShiftPodServiceAccount = "cass-operator-cassandra-default-sa"
)

// calculateNodeAffinity provides a way to decide where to schedule pods within a statefulset based on labels
Expand Down Expand Up @@ -740,7 +739,7 @@ func buildContainers(dc *api.CassandraDatacenter, baseTemplate *corev1.PodTempla
return nil
}

func buildPodTemplateSpec(dc *api.CassandraDatacenter, rack api.Rack, addLegacyInternodeMount, openShift bool) (*corev1.PodTemplateSpec, error) {
func buildPodTemplateSpec(dc *api.CassandraDatacenter, rack api.Rack, addLegacyInternodeMount bool) (*corev1.PodTemplateSpec, error) {

baseTemplate := dc.Spec.PodTemplateSpec.DeepCopy()

Expand All @@ -749,9 +748,6 @@ func buildPodTemplateSpec(dc *api.CassandraDatacenter, rack api.Rack, addLegacyI
}

// Service Account
if openShift {
baseTemplate.Spec.ServiceAccountName = OpenShiftPodServiceAccount
}

if dc.Spec.ServiceAccountName != "" {
baseTemplate.Spec.ServiceAccountName = dc.Spec.ServiceAccountName
Expand Down
64 changes: 15 additions & 49 deletions pkg/reconciliation/construct_podtemplatespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_containers_merge(t *testing.T)
},
},
}
got, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
got, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)

assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")
assert.Equal(t, 3, len(got.Spec.Containers))
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_initcontainers_merge(t *testin
ConfigBuilderResources: testContainer.Resources,
},
}
got, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
got, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)

assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")
assert.Equal(t, 2, len(got.Spec.InitContainers))
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_add_initContainer_after_config
},
}

podTemplateSpec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
podTemplateSpec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)

assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")

Expand Down Expand Up @@ -704,7 +704,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_add_initContainer_with_volumes
},
}

podTemplateSpec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true, false)
podTemplateSpec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true)

assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")

Expand Down Expand Up @@ -814,7 +814,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_add_container_with_volumes(t *
},
}

podTemplateSpec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true, false)
podTemplateSpec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true)

assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")

Expand Down Expand Up @@ -871,7 +871,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_add_container_with_volumes(t *
testZoneRack := dc.Spec.Racks[0]
testZoneRack.NodeAffinityLabels = map[string]string{zoneLabel: "testzone"}
dc.Spec.Racks[0] = testZoneRack
podTemplateSpec, err = buildPodTemplateSpec(dc, testZoneRack, false, false)
podTemplateSpec, err = buildPodTemplateSpec(dc, testZoneRack, false)
assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")

volumes = podTemplateSpec.Spec.Volumes
Expand Down Expand Up @@ -971,7 +971,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_labels_merge(t *testing.T) {
}
dc.Spec.PodTemplateSpec.Labels = map[string]string{"abc": "123"}

spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)
got := spec.Labels

expected := dc.GetRackLabels("testrack")
Expand Down Expand Up @@ -1005,7 +1005,7 @@ func TestCassandraDatacenter_buildContainers_additional_labels(t *testing.T) {
}
dc.Spec.PodTemplateSpec.Labels = map[string]string{"abc": "123"}

spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)
got := spec.Labels

expected := dc.GetRackLabels("testrack")
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_overrideSecurityContext(t *tes
},
}

spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)

assert.NoError(t, err, "should not have gotten an error when building podTemplateSpec")
assert.NotNil(t, spec)
Expand Down Expand Up @@ -1098,7 +1098,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_do_not_propagate_volumes(t *te
},
}

spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true, false)
spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true)
assert.NoError(t, err, "should not have gotten error when building podTemplateSpec")

initContainers := spec.Spec.InitContainers
Expand Down Expand Up @@ -1163,7 +1163,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_clientImage(t *testing.T) {

// 4.0 should not have the client image or new config builder, 4.1 should

spec40, err := buildPodTemplateSpec(dc40, dc40.Spec.Racks[0], false, false)
spec40, err := buildPodTemplateSpec(dc40, dc40.Spec.Racks[0], false)
assert.NoError(err, "should not have gotten error when building podTemplateSpec")

initContainers := spec40.Spec.InitContainers
Expand All @@ -1178,7 +1178,7 @@ func TestCassandraDatacenter_buildPodTemplateSpec_clientImage(t *testing.T) {
assert.True(volumesContains(volumes, volumeNameMatcher("server-logs")))
assert.True(volumesContains(volumes, volumeNameMatcher("vector-lib")))

spec41, err := buildPodTemplateSpec(dc41, dc41.Spec.Racks[0], false, false)
spec41, err := buildPodTemplateSpec(dc41, dc41.Spec.Racks[0], false)
assert.NoError(err, "should not have gotten error when building podTemplateSpec")

initContainers = spec41.Spec.InitContainers
Expand Down Expand Up @@ -1207,40 +1207,6 @@ func TestCassandraDatacenter_buildPodTemplateSpec_clientImage(t *testing.T) {
assert.True(volumesContains(volumes, volumeNameMatcher("vector-lib")))
}

func TestCassandraDatacenter_buildPodTemplateSpec_openShift(t *testing.T) {
assert := assert.New(t)

dc := &api.CassandraDatacenter{
Spec: api.CassandraDatacenterSpec{
ClusterName: "bob",
ServerType: "cassandra",
ServerVersion: "4.1.2",
Racks: []api.Rack{
{
Name: "default",
},
},
},
}

spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], true, false)
assert.NoError(err, "should not have gotten error when building podTemplateSpec")

assert.Equal(spec.Spec.ServiceAccountName, "", "no default serviceAccount is set")

spec, err = buildPodTemplateSpec(dc, dc.Spec.Racks[0], true, true)
assert.NoError(err, "should not have gotten error when building podTemplateSpec")

assert.Equal(spec.Spec.ServiceAccountName, OpenShiftPodServiceAccount, "missing serviceAccount when running under OLM")

dc.Spec.ServiceAccountName = "overrideSA"

spec, err = buildPodTemplateSpec(dc, dc.Spec.Racks[0], true, true)
assert.NoError(err, "should not have gotten error when building podTemplateSpec")

assert.Equal(spec.Spec.ServiceAccountName, "overrideSA", "under OLM the serviceAccountName must be overwritable")
}

func TestCassandraDatacenter_buildContainers_DisableSystemLoggerSidecar(t *testing.T) {
dc := &api.CassandraDatacenter{
Spec: api.CassandraDatacenterSpec{
Expand Down Expand Up @@ -1431,7 +1397,7 @@ func TestTolerations(t *testing.T) {
},
}

spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
spec, err := buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)

assert.NoError(t, err, "failed to build PodTemplateSpec")
// using ElementsMatch instead of Equal because we do not really care about ordering.
Expand Down Expand Up @@ -1468,7 +1434,7 @@ func TestTolerations(t *testing.T) {
},
}

spec, err = buildPodTemplateSpec(dc, dc.Spec.Racks[0], false, false)
spec, err = buildPodTemplateSpec(dc, dc.Spec.Racks[0], false)

assert.NoError(t, err, "failed to build PodTemplateSpec")
// using ElementsMatch instead of Equal because we do not really care about ordering.
Expand Down Expand Up @@ -1688,7 +1654,7 @@ func TestServiceAccountPrecedence(t *testing.T) {
}

for _, test := range tests {
pds, err := buildPodTemplateSpec(test.dc, test.dc.Spec.Racks[0], false, false)
pds, err := buildPodTemplateSpec(test.dc, test.dc.Spec.Racks[0], false)
assert.NoError(err)
assert.Equal(test.accountName, pds.Spec.ServiceAccountName)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/reconciliation/construct_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func newStatefulSetForCassandraDatacenter(
sts *appsv1.StatefulSet,
rackName string,
dc *api.CassandraDatacenter,
replicaCount int,
openShift bool) (*appsv1.StatefulSet, error) {
replicaCount int) (*appsv1.StatefulSet, error) {

replicaCountInt32 := int32(replicaCount)

Expand Down Expand Up @@ -113,7 +112,7 @@ func newStatefulSetForCassandraDatacenter(

nsName := newNamespacedNameForStatefulSet(dc, rackName)

template, err := buildPodTemplateSpec(dc, rack, legacyInternodeMount(dc, sts), openShift)
template, err := buildPodTemplateSpec(dc, rack, legacyInternodeMount(dc, sts))
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 214035d

Please sign in to comment.