Skip to content

Commit

Permalink
130 workloads (#158)
Browse files Browse the repository at this point in the history
* added dseWorkloads field

* added jvm_extra_opts logic

* WIP - added second piece of workload logic

* WIP - typo fixes

* unit test fixes

* unit test fixes

* Added webhook validation for dse workloads

* grammar fixup
  • Loading branch information
respringer authored Jul 15, 2020
1 parent 721056a commit ade4246
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ spec:
configBuilderImage:
description: Container image for the config builder init container.
type: string
dseWorkloads:
properties:
analyticsEnabled:
type: boolean
graphEnabled:
type: boolean
searchEnabled:
type: boolean
type: object
forceUpgradeRacks:
description: Rack names in this list are set to the latest StatefulSet
configuration even if Cassandra nodes are down. Use this to recover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ spec:
configBuilderImage:
description: Container image for the config builder init container.
type: string
dseWorkloads:
properties:
analyticsEnabled:
type: boolean
graphEnabled:
type: boolean
searchEnabled:
type: boolean
type: object
forceUpgradeRacks:
description: Rack names in this list are set to the latest StatefulSet
configuration even if Cassandra nodes are down. Use this to recover
Expand Down
33 changes: 32 additions & 1 deletion operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ type CassandraDatacenterSpec struct {
// roll out.
ForceUpgradeRacks []string `json:"forceUpgradeRacks,omitempty"`

DseWorkloads *DseWorkloads `json:"dseWorkloads,omitempty"`

// PodTemplate provides customisation options (labels, annotations, affinity rules, resource requests, and so on) for the cassandra pods
PodTemplateSpec *corev1.PodTemplateSpec `json:"podTemplateSpec,omitempty"`

Expand All @@ -224,6 +226,12 @@ type CassandraDatacenterSpec struct {
Reaper *ReaperConfig `json:"reaper,omitempty"`
}

type DseWorkloads struct {
AnalyticsEnabled bool `json:"analyticsEnabled,omitempty"`
GraphEnabled bool `json:"graphEnabled,omitempty"`
SearchEnabled bool `json:"searchEnabled,omitempty"`
}

type StorageConfig struct {
CassandraDataVolumeClaimSpec *corev1.PersistentVolumeClaimSpec `json:"cassandraDataVolumeClaimSpec,omitempty"`
}
Expand Down Expand Up @@ -504,7 +512,30 @@ func (dc *CassandraDatacenter) GetConfigAsJSON() (string, error) {
// cassandra.yaml whenever the seed nodes change.
seeds := []string{dc.GetSeedServiceName()}
seeds = append(seeds, dc.Spec.AdditionalSeeds...)
modelValues := serverconfig.GetModelValues(seeds, dc.Spec.ClusterName, dc.Name)

graphEnabled := 0
solrEnabled := 0
sparkEnabled := 0

if dc.Spec.ServerType == "dse" && dc.Spec.DseWorkloads != nil {
if dc.Spec.DseWorkloads.AnalyticsEnabled == true {
sparkEnabled = 1
}
if dc.Spec.DseWorkloads.GraphEnabled == true {
graphEnabled = 1
}
if dc.Spec.DseWorkloads.SearchEnabled == true {
solrEnabled = 1
}
}

modelValues := serverconfig.GetModelValues(
seeds,
dc.Spec.ClusterName,
dc.Name,
graphEnabled,
solrEnabled,
sparkEnabled)

var modelBytes []byte

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func Test_GenerateBaseConfigString(t *testing.T) {
Config: []byte("{\"cassandra-yaml\":{\"authenticator\":\"AllowAllAuthenticator\",\"batch_size_fail_threshold_in_kb\":1280}}"),
},
},
want: `{"cassandra-yaml":{"authenticator":"AllowAllAuthenticator","batch_size_fail_threshold_in_kb":1280},"cluster-info":{"name":"exampleCluster","seeds":"exampleCluster-seed-service"},"datacenter-info":{"name":"exampleDC"}}`,
want: `{"cassandra-yaml":{"authenticator":"AllowAllAuthenticator","batch_size_fail_threshold_in_kb":1280},"cluster-info":{"name":"exampleCluster","seeds":"exampleCluster-seed-service"},"datacenter-info":{"graph-enabled":0,"name":"exampleDC","solr-enabled":0,"spark-enabled":0}}`,
errString: "",
},
{
Expand Down
7 changes: 6 additions & 1 deletion operator/pkg/apis/cassandra/v1beta1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func attemptedTo(action string, actionStrArgs ...interface{}) error {
var msg string
if actionStrArgs != nil {
msg = fmt.Sprintf(action, actionStrArgs...)

} else {
msg = action
}
Expand All @@ -45,6 +44,12 @@ func ValidateSingleDatacenter(dc CassandraDatacenter) error {
return err
}

if dc.Spec.ServerType == "cassandra" && dc.Spec.DseWorkloads != nil {
if dc.Spec.DseWorkloads.AnalyticsEnabled || dc.Spec.DseWorkloads.GraphEnabled || dc.Spec.DseWorkloads.SearchEnabled {
return attemptedTo("enable DSE workloads if server type is Cassandra")
}
}

if dc.Spec.ServerType == "cassandra" {
switch dc.Spec.ServerVersion {
case "3.11.6":
Expand Down
32 changes: 32 additions & 0 deletions operator/pkg/apis/cassandra/v1beta1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,38 @@ func Test_ValidateSingleDatacenter(t *testing.T) {
},
errString: "use unsupported Cassandra version '6.8.0'",
},
{
name: "Dse Workloads in Cassandra Invalid",
dc: &CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Name: "exampleDC",
},
Spec: CassandraDatacenterSpec{
ServerType: "cassandra",
ServerVersion: "6.8.0",
DseWorkloads: &DseWorkloads{
AnalyticsEnabled: true,
},
},
},
errString: "CassandraDatacenter write rejected, attempted to enable DSE workloads if server type is Cassandra",
},
{
name: "Dse Workloads in Dse valid",
dc: &CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Name: "exampleDC",
},
Spec: CassandraDatacenterSpec{
ServerType: "dse",
ServerVersion: "6.8.1",
DseWorkloads: &DseWorkloads{
AnalyticsEnabled: true,
},
},
},
errString: "",
},
}

for _, tt := range tests {
Expand Down
21 changes: 21 additions & 0 deletions operator/pkg/apis/cassandra/v1beta1/zz_generated.deepcopy.go

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

24 changes: 22 additions & 2 deletions operator/pkg/reconciliation/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package reconciliation

import (
"fmt"
"os"
"k8s.io/api/batch/v1"
"os"

api "github.com/datastax/cass-operator/operator/pkg/apis/cassandra/v1beta1"
"github.com/datastax/cass-operator/operator/pkg/httphelper"
Expand Down Expand Up @@ -362,6 +362,21 @@ func probe(port int, path string, initDelay int, period int) *corev1.Probe {
}
}

func getJvmExtraOpts(dc *api.CassandraDatacenter) string {
flags := ""

if dc.Spec.DseWorkloads.AnalyticsEnabled == true {
flags += "-k "
}
if dc.Spec.DseWorkloads.GraphEnabled == true {
flags += "-g "
}
if dc.Spec.DseWorkloads.SearchEnabled == true {
flags += "-s"
}
return flags
}

func buildContainers(dc *api.CassandraDatacenter, serverVolumeMounts []corev1.VolumeMount) ([]corev1.Container, error) {
// cassandra container
cassContainer := corev1.Container{}
Expand All @@ -383,6 +398,12 @@ func buildContainers(dc *api.CassandraDatacenter, serverVolumeMounts []corev1.Vo
{Name: "DSE_MGMT_EXPLICIT_START", Value: "true"},
}

if dc.Spec.ServerType == "dse" && dc.Spec.DseWorkloads != nil {
cassContainer.Env = append(
cassContainer.Env,
corev1.EnvVar{Name: "JVM_EXTRA_OPTS", Value: getJvmExtraOpts(dc)})
}

ports, err := dc.GetContainerPorts()
if err != nil {
return nil, err
Expand Down Expand Up @@ -561,4 +582,3 @@ func buildInitReaperSchemaJob(dc *api.CassandraDatacenter) *v1.Job {
},
}
}

14 changes: 12 additions & 2 deletions operator/pkg/serverconfig/configgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import (
type NodeConfig map[string]interface{}

// GetModelValues will gather the cluster model values for cluster and datacenter
func GetModelValues(seeds []string, clusterName string, dcName string) NodeConfig {
func GetModelValues(
seeds []string,
clusterName string,
dcName string,
graphEnabled int,
solrEnabled int,
sparkEnabled int) NodeConfig {

seedsString := strings.Join(seeds, ",")

// Note: the operator does not currently support graph, solr, and spark
Expand All @@ -21,7 +28,10 @@ func GetModelValues(seeds []string, clusterName string, dcName string) NodeConfi
"seeds": seedsString,
},
"datacenter-info": NodeConfig{
"name": dcName,
"name": dcName,
"graph-enabled": graphEnabled,
"solr-enabled": solrEnabled,
"spark-enabled": sparkEnabled,
}}

return modelValues
Expand Down
Loading

0 comments on commit ade4246

Please sign in to comment.