diff --git a/go.mod b/go.mod index 736b7716..072ebdd2 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( k8s.io/klog/v2 v2.130.1 kmodules.xyz/client-go v0.30.13 kmodules.xyz/custom-resources v0.30.0 - kubedb.dev/apimachinery v0.47.1-0.20240822044956-3da387889ca5 + kubedb.dev/apimachinery v0.47.1-0.20240905094616-0f3ede79a000 sigs.k8s.io/controller-runtime v0.18.4 xorm.io/xorm v1.3.6 ) diff --git a/go.sum b/go.sum index 4b971368..0f3aaa28 100644 --- a/go.sum +++ b/go.sum @@ -802,8 +802,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9 kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI= kmodules.xyz/offshoot-api v0.30.0 h1:dq9F93pu4Q8rL9oTcCk+vGGy8vpS7RNt0GSwx7Bvhec= kmodules.xyz/offshoot-api v0.30.0/go.mod h1:o9VoA3ImZMDBp3lpLb8+kc2d/KBxioRwCpaKDfLIyDw= -kubedb.dev/apimachinery v0.47.1-0.20240822044956-3da387889ca5 h1:+gfLsub9ZyzO9XSydpELJPz1WUsp1rjAR6p2JF3b34k= -kubedb.dev/apimachinery v0.47.1-0.20240822044956-3da387889ca5/go.mod h1:VSzi3IpellQ8ZqtEu3FokfN6siZdG2AB87wPXv9Xh54= +kubedb.dev/apimachinery v0.47.1-0.20240905094616-0f3ede79a000 h1:eU5wtcyAPXJpGqiJ7yWrYBFoT4QsGT5t95bCE56w/os= +kubedb.dev/apimachinery v0.47.1-0.20240905094616-0f3ede79a000/go.mod h1:iD6XKg9Blvfd9iYEO0N9GKiSz6r+yzEPZnfkYdESNG4= kubeops.dev/petset v0.0.5-0.20240603165102-e2d9decb8abe h1:uWyps3VIDFwGuL0yQa0eMGaLg4ofVwpy59U14Trxnz8= kubeops.dev/petset v0.0.5-0.20240603165102-e2d9decb8abe/go.mod h1:A15vh0r979NsvL65DTIZKWsa/NoX9VapHBAEw1ZsdYI= lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= diff --git a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/cassandra_version_types.go b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/cassandra_version_types.go index 33d37606..7d5a4c01 100644 --- a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/cassandra_version_types.go +++ b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/cassandra_version_types.go @@ -21,7 +21,7 @@ import ( ) const ( - ResourceCodeCassandraVersion = "csversion" + ResourceCodeCassandraVersion = "casversion" ResourceKindCassandraVersion = "CassandraVersion" ResourceSingularCassandraVersion = "cassandraversion" ResourcePluralCassandraVersion = "cassandraversions" @@ -36,7 +36,7 @@ const ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:object:root=true -// +kubebuilder:resource:path=cassandraversions,singular=cassandraversion,scope=Cluster,shortName=csversion,categories={catalog,kubedb,appscode} +// +kubebuilder:resource:path=cassandraversions,singular=cassandraversion,scope=Cluster,shortName=casversion,categories={catalog,kubedb,appscode} // +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version" // +kubebuilder:printcolumn:name="DB_IMAGE",type="string",JSONPath=".spec.db.image" // +kubebuilder:printcolumn:name="Deprecated",type="boolean",JSONPath=".spec.deprecated" diff --git a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/memcached_version_types.go b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/memcached_version_types.go index 1ab939be..d3b602dc 100644 --- a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/memcached_version_types.go +++ b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/memcached_version_types.go @@ -58,6 +58,8 @@ type MemcachedVersionSpec struct { Deprecated bool `json:"deprecated,omitempty"` // PSP names PodSecurityPolicies MemcachedVersionPodSecurityPolicy `json:"podSecurityPolicies"` + // update constraints + UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"` // SecurityContext is for the additional config for the DB container // +optional SecurityContext SecurityContext `json:"securityContext"` diff --git a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/openapi_generated.go b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/openapi_generated.go index 67ce3010..2478a3f1 100644 --- a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/openapi_generated.go +++ b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/openapi_generated.go @@ -28083,6 +28083,13 @@ func schema_apimachinery_apis_catalog_v1alpha1_MemcachedVersionSpec(ref common.R Ref: ref("kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionPodSecurityPolicy"), }, }, + "updateConstraints": { + SchemaProps: spec.SchemaProps{ + Description: "update constraints", + Default: map[string]interface{}{}, + Ref: ref("kubedb.dev/apimachinery/apis/catalog/v1alpha1.UpdateConstraints"), + }, + }, "securityContext": { SchemaProps: spec.SchemaProps{ Description: "SecurityContext is for the additional config for the DB container", @@ -28108,7 +28115,7 @@ func schema_apimachinery_apis_catalog_v1alpha1_MemcachedVersionSpec(ref common.R }, }, Dependencies: []string{ - "kubedb.dev/apimachinery/apis/catalog/v1alpha1.ChartInfo", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionDatabase", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionExporter", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionPodSecurityPolicy", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.SecurityContext"}, + "kubedb.dev/apimachinery/apis/catalog/v1alpha1.ChartInfo", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionDatabase", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionExporter", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.MemcachedVersionPodSecurityPolicy", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.SecurityContext", "kubedb.dev/apimachinery/apis/catalog/v1alpha1.UpdateConstraints"}, } } diff --git a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/zz_generated.deepcopy.go b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/zz_generated.deepcopy.go index 90eac572..ff7292fc 100644 --- a/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/zz_generated.deepcopy.go @@ -1702,6 +1702,7 @@ func (in *MemcachedVersionSpec) DeepCopyInto(out *MemcachedVersionSpec) { out.DB = in.DB out.Exporter = in.Exporter out.PodSecurityPolicies = in.PodSecurityPolicies + in.UpdateConstraints.DeepCopyInto(&out.UpdateConstraints) in.SecurityContext.DeepCopyInto(&out.SecurityContext) if in.UI != nil { in, out := &in.UI, &out.UI diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go index f42ae03a..3e9a55a5 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go @@ -1348,14 +1348,54 @@ const ( // =========================== Cassandra Constants ============================ const ( - CassandraNativeTCP = 9042 + CassandraNativeTcpPort = 9042 + CassandraInterNodePort = 7000 + CassandraJmxPort = 7199 + + CassandraUserAdmin = "admin" + + CassandraOperatorConfigDir = "/tmp/config/operator-config" + CassandraMainConfigDir = "/etc/cassandra" + CassandraCustomConfigDir = "/tmp/config/custom-config" + CassandraScriptDir = "/tmp/sc" + + CassandraVolumeOperatorConfig = "operator-config-volume" + CassandraVolumeMainConfig = "main-config-volume" + CassandraVolumeCustomConfig = "custom-config" + CassandraVolumeScript = "script-volume" + CassandraVolumeData = "data" CassandraDataDir = "/var/lib/cassandra" + CassandraServerLogDir = "var/log/cassandra-server/cassandra-server.log" + CassandraServerErrorLogDir = "var/log/cassandra-server/cassandra-server.err.log" CassandraContainerName = "cassandra" CassandraInitContainerName = "cassandra-init" + CassandraMainConfigFile = "cassandra.yaml" CassandraRackConfigFile = "rack-config.yaml" CassandraStandalone = "standalone" CassandraServerConfigFile = "server-config.yaml" + + EnvNameCassandraEndpointSnitch = "CASSANDRA_ENDPOINT_SNITCH" + EnvValCassandraEndpointSnitch = "GossipingPropertyFileSnitch" + + EnvNameCassandraRack = "CASSANDRA_RACK" + EnvNameCassandraPodNamespace = "CASSANDRA_POD_NAMESPACE" + EnvNameCassandraService = "CASSANDRA_SERVICE" + EnvNameCassandraMaxHeapSize = "MAX_HEAP_SIZE" + EnvValCassandraMaxHeapSize = "512M" + EnvNameCassandraHeapNewSize = "HEAP_NEWSIZE" + EnvValCassandraHeapNewSize = "100M" + EnvNameCassandraListenAddress = "CASSANDRA_LISTEN_ADDRESS" + EnvNameCassandraBroadcastAddress = "CASSANDRA_BROADCAST_ADDRESS" + EnvNameCassandraRpcAddress = "CASSANDRA_RPC_ADDRESS" + EnvValCassandraRpcAddress = "0.0.0.0" + EnvNameCassandraNumTokens = "CASSANDRA_NUM_TOKENS" + EnvValCassandraNumTokens = "256" + EnvNameCassandraStartRpc = "CASSANDRA_START_RPC" + EnvNameCassandraSeeds = "CASSANDRA_SEEDS" + EnvNameCassandraPodName = "CASSANDRA_POD_NAME" + EnvNameCassandraUser = "CASSANDRA_USER" + EnvNameCassandraPassword = "CASSANDRA_PASSWORD" ) // Resource kind related constants diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_helpers.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_helpers.go index f82bd991..d84dcdea 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_helpers.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_helpers.go @@ -29,7 +29,6 @@ import ( "gomodules.xyz/pointer" core "k8s.io/api/core/v1" - "k8s.io/api/resource/v1alpha2" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" @@ -63,7 +62,7 @@ func (r CassandraApp) Type() appcat.AppType { // Owner returns owner reference to resources func (r *Cassandra) Owner() *meta.OwnerReference { - return meta.NewControllerRef(r, v1alpha2.SchemeGroupVersion.WithKind(r.ResourceKind())) + return meta.NewControllerRef(r, SchemeGroupVersion.WithKind(r.ResourceKind())) } func (r *Cassandra) ResourceKind() string { @@ -181,7 +180,7 @@ func (r *Cassandra) GetConnectionScheme() string { func (r *Cassandra) SetHealthCheckerDefaults() { if r.Spec.HealthChecker.PeriodSeconds == nil { - r.Spec.HealthChecker.PeriodSeconds = pointer.Int32P(10) + r.Spec.HealthChecker.PeriodSeconds = pointer.Int32P(60) } if r.Spec.HealthChecker.TimeoutSeconds == nil { r.Spec.HealthChecker.TimeoutSeconds = pointer.Int32P(10) @@ -200,10 +199,26 @@ func (r *Cassandra) ResourceSingular() string { } func (r *Cassandra) SetDefaults() { - var csVersion catalog.CassandraVersion + if r.Spec.DeletionPolicy == "" { + r.Spec.DeletionPolicy = TerminationPolicyDelete + } + + if !r.Spec.DisableSecurity { + if r.Spec.AuthSecret == nil { + r.Spec.AuthSecret = &SecretReference{ + LocalObjectReference: core.LocalObjectReference{ + Name: r.DefaultUserCredSecretName(kubedb.CassandraUserAdmin), + }, + ExternallyManaged: false, + } + } + + } + + var casVersion catalog.CassandraVersion err := DefaultClient.Get(context.TODO(), types.NamespacedName{ Name: r.Spec.Version, - }, &csVersion) + }, &casVersion) if err != nil { klog.Errorf("can't get the cassandra version object %s for %s \n", err.Error(), r.Spec.Version) return @@ -238,7 +253,7 @@ func (r *Cassandra) SetDefaults() { if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) { apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources) } - r.setDefaultContainerSecurityContext(&csVersion, rack.PodTemplate) + r.setDefaultContainerSecurityContext(&casVersion, rack.PodTemplate) racks[index] = rack } r.Spec.Topology.Rack = racks @@ -246,9 +261,6 @@ func (r *Cassandra) SetDefaults() { if r.Spec.Replicas == nil { r.Spec.Replicas = pointer.Int32P(1) } - if r.Spec.DeletionPolicy == "" { - r.Spec.DeletionPolicy = TerminationPolicyDelete - } if r.Spec.StorageType == "" { r.Spec.StorageType = StorageTypeDurable } @@ -256,7 +268,7 @@ func (r *Cassandra) SetDefaults() { if r.Spec.PodTemplate == nil { r.Spec.PodTemplate = &ofst.PodTemplateSpec{} } - r.setDefaultContainerSecurityContext(&csVersion, r.Spec.PodTemplate) + r.setDefaultContainerSecurityContext(&casVersion, r.Spec.PodTemplate) dbContainer := coreutil.GetContainerByName(r.Spec.PodTemplate.Spec.Containers, kubedb.CassandraContainerName) if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) { apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources) diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_types.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_types.go index b842f7c4..7ebb6a87 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_types.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_types.go @@ -27,7 +27,7 @@ const ( ResourceKindCassandra = "Cassandra" ResourceSingularCassandra = "cassandra" ResourcePluralCassandra = "cassandras" - ResourceCodeCassandra = "cs" + ResourceCodeCassandra = "cas" ) // +genclient @@ -36,7 +36,7 @@ const ( // +kubebuilder:object:root=true // +kubebuilder:subresource:status -// +kubebuilder:resource:path=cassandras,singular=cassandra,shortName=cs,categories={datastore,kubedb,appscode,all} +// +kubebuilder:resource:path=cassandras,singular=cassandra,shortName=cas,categories={datastore,kubedb,appscode,all} // +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".apiVersion" // +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version" // +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase" @@ -54,11 +54,11 @@ type CassandraSpec struct { // Version of Cassandra to be deployed. Version string `json:"version"` - // Number of instances to deploy for a Cassandra database. + // Number of replicas for Cassandra database. // +optional Replicas *int32 `json:"replicas,omitempty"` - // rack + // Cassandra Topology for Racks // +optional Topology *Topology `json:"topology,omitempty"` @@ -96,12 +96,12 @@ type CassandraSpec struct { // HealthChecker defines attributes of the health checker // +optional - // +kubebuilder:default={periodSeconds: 20, timeoutSeconds: 10, failureThreshold: 3} + // +kubebuilder:default={periodSeconds: 30, timeoutSeconds: 10, failureThreshold: 3} HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"` } type Topology struct { - // cassandra rack Structure + // cassandra rack structure Rack []RackSpec `json:"rack,omitempty"` } diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_webhook.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_webhook.go new file mode 100644 index 00000000..c85e1e89 --- /dev/null +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/cassandra_webhook.go @@ -0,0 +1,303 @@ +/* +Copyright AppsCode Inc. and Contributors + +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 v1alpha2 + +import ( + "context" + "errors" + "fmt" + + catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1" + "kubedb.dev/apimachinery/apis/kubedb" + + core "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/validation/field" + ofst "kmodules.xyz/offshoot-api/api/v2" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/webhook" + "sigs.k8s.io/controller-runtime/pkg/webhook/admission" +) + +// log is for logging in this package. +var cassandralog = logf.Log.WithName("cassandra-resource") + +var _ webhook.Defaulter = &Cassandra{} + +// Default implements webhook.Defaulter so a webhook will be registered for the type +func (r *Cassandra) Default() { + if r == nil { + return + } + cassandralog.Info("default", "name", r.Name) + r.SetDefaults() +} + +var _ webhook.Validator = &Cassandra{} + +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type +func (r *Cassandra) ValidateCreate() (admission.Warnings, error) { + cassandralog.Info("validate create", "name", r.Name) + return nil, r.ValidateCreateOrUpdate() +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type +func (r *Cassandra) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { + cassandralog.Info("validate update", "name", r.Name) + return nil, r.ValidateCreateOrUpdate() +} + +// ValidateDelete implements webhook.Validator so a webhook will be registered for the type +func (r *Cassandra) ValidateDelete() (admission.Warnings, error) { + cassandralog.Info("validate delete", "name", r.Name) + + var allErr field.ErrorList + if r.Spec.DeletionPolicy == TerminationPolicyDoNotTerminate { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"), + r.Name, + "Can not delete as terminationPolicy is set to \"DoNotTerminate\"")) + return nil, apierrors.NewInvalid(schema.GroupKind{Group: "Cassandra.kubedb.com", Kind: "Cassandra"}, r.Name, allErr) + } + return nil, nil +} + +func (r *Cassandra) ValidateCreateOrUpdate() error { + var allErr field.ErrorList + + if r.Spec.Version == "" { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("version"), + r.Name, + "spec.version' is missing")) + return apierrors.NewInvalid(schema.GroupKind{Group: "Cassandra.kubedb.com", Kind: "Cassandra"}, r.Name, allErr) + } else { + err := r.ValidateVersion(r) + if err != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("version"), + r.Spec.Version, + err.Error())) + return apierrors.NewInvalid(schema.GroupKind{Group: "cassandra.kubedb.com", Kind: "cassandra"}, r.Name, allErr) + } + } + + if r.Spec.Topology != nil { + rackName := map[string]bool{} + racks := r.Spec.Topology.Rack + for _, rack := range racks { + if rack.Replicas != nil && *rack.Replicas <= 0 { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child("replicas"), + r.Name, + "number of replicas can't be 0 or less")) + } + if rackName[rack.Name] { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child(rack.Name), + r.Name, + "rack name is duplicated, use different rack name")) + } + rackName[rack.Name] = true + + allErr = r.validateClusterStorageType(rack, allErr) + + err := r.validateVolumes(rack.PodTemplate) + if err != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child("podTemplate").Child("spec").Child("volumes"), + r.Name, + err.Error())) + } + err = r.validateVolumesMountPaths(rack.PodTemplate) + if err != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child("podTemplate").Child("spec").Child("volumeMounts"), + r.Name, + err.Error())) + } + } + if r.Spec.PodTemplate != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("podTemplate"), + r.Name, + "PodTemplate should be nil in Topology")) + } + + if r.Spec.Replicas != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("replica"), + r.Name, + "replica should be nil in Topology")) + } + + if r.Spec.StorageType != "" { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("storageType"), + r.Name, + "StorageType should be empty in Topology")) + } + + if r.Spec.Storage != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("storage"), + r.Name, + "storage should be nil in Topology")) + } + + } else { + // number of replicas can not be 0 or less + if r.Spec.Replicas != nil && *r.Spec.Replicas <= 0 { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("replicas"), + r.Name, + "number of replicas can't be 0 or less")) + } + + // number of replicas can not be greater than 1 + if r.Spec.Replicas != nil && *r.Spec.Replicas > 1 { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("replicas"), + r.Name, + "number of replicas can't be greater than 1 in standalone mode")) + } + err := r.validateVolumes(r.Spec.PodTemplate) + if err != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("podTemplate").Child("spec").Child("volumes"), + r.Name, + err.Error())) + } + err = r.validateVolumesMountPaths(r.Spec.PodTemplate) + if err != nil { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("podTemplate").Child("spec").Child("volumeMounts"), + r.Name, + err.Error())) + } + + allErr = r.validateStandaloneStorageType(r.Spec.StorageType, r.Spec.Storage, allErr) + } + + if len(allErr) == 0 { + return nil + } + return apierrors.NewInvalid(schema.GroupKind{Group: "Cassandra.kubedb.com", Kind: "Cassandra"}, r.Name, allErr) +} + +func (c *Cassandra) validateStandaloneStorageType(storageType StorageType, storage *core.PersistentVolumeClaimSpec, allErr field.ErrorList) field.ErrorList { + if storageType == "" { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("storageType"), + c.Name, + "StorageType can not be empty")) + } else { + if storageType != StorageTypeDurable && c.Spec.StorageType != StorageTypeEphemeral { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("storageType"), + c.Name, + "StorageType should be either durable or ephemeral")) + } + } + + if storage == nil && c.Spec.StorageType == StorageTypeDurable { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("storage"), + c.Name, + "Storage can't be empty when StorageType is durable")) + } + + return allErr +} + +func (c *Cassandra) validateClusterStorageType(rack RackSpec, allErr field.ErrorList) field.ErrorList { + if rack.StorageType == "" { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child(rack.Name).Child("storageType"), + c.Name, + "StorageType can not be empty")) + } else { + if rack.StorageType != StorageTypeDurable && rack.StorageType != StorageTypeEphemeral { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child(rack.Name).Child("storageType"), + rack.StorageType, + "StorageType should be either durable or ephemeral")) + } + } + if rack.Storage == nil && rack.StorageType == StorageTypeDurable { + allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("Topology").Child(rack.Name).Child("storage"), + c.Name, + "Storage can't be empty when StorageType is durable")) + } + return allErr +} + +func (r *Cassandra) ValidateVersion(db *Cassandra) error { + chVersion := catalog.CassandraVersion{} + err := DefaultClient.Get(context.TODO(), types.NamespacedName{Name: db.Spec.Version}, &chVersion) + if err != nil { + // fmt.Sprint(db.Spec.Version, "version not supported") + return errors.New(fmt.Sprint("version ", db.Spec.Version, " not supported")) + } + return nil +} + +var cassandraReservedVolumes = []string{ + kubedb.CassandraVolumeData, +} + +func (r *Cassandra) validateVolumes(podTemplate *ofst.PodTemplateSpec) error { + if podTemplate.Spec.Volumes == nil { + return nil + } + rsv := make([]string, len(cassandraReservedVolumes)) + copy(rsv, cassandraReservedVolumes) + volumes := podTemplate.Spec.Volumes + for _, rv := range rsv { + for _, ugv := range volumes { + if ugv.Name == rv { + return errors.New("Cannot use a reserve volume name: " + rv) + } + } + } + return nil +} + +var cassandraReservedVolumeMountPaths = []string{ + kubedb.CassandraDataDir, +} + +func (r *Cassandra) validateVolumesMountPaths(podTemplate *ofst.PodTemplateSpec) error { + if podTemplate == nil { + return nil + } + if podTemplate.Spec.Containers == nil { + return nil + } + + for _, rvmp := range cassandraReservedVolumeMountPaths { + containerList := podTemplate.Spec.Containers + for i := range containerList { + mountPathList := containerList[i].VolumeMounts + for j := range mountPathList { + if mountPathList[j].MountPath == rvmp { + return errors.New("Can't use a reserve volume mount path name: " + rvmp) + } + } + } + } + + if podTemplate.Spec.InitContainers == nil { + return nil + } + + for _, rvmp := range cassandraReservedVolumeMountPaths { + containerList := podTemplate.Spec.InitContainers + for i := range containerList { + mountPathList := containerList[i].VolumeMounts + for j := range mountPathList { + if mountPathList[j].MountPath == rvmp { + return errors.New("Can't use a reserve volume mount path name: " + rvmp) + } + } + } + } + return nil +} diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mssqlserver_helpers.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mssqlserver_helpers.go index 6f0a31d4..482185db 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mssqlserver_helpers.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mssqlserver_helpers.go @@ -377,6 +377,16 @@ func (m *MSSQLServer) SetDefaults() { m.SetHealthCheckerDefaults() m.setDefaultContainerResourceLimits(m.Spec.PodTemplate) + + m.Spec.Monitor.SetDefaults() + if m.Spec.Monitor != nil && m.Spec.Monitor.Prometheus != nil { + if m.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsUser == nil { + m.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsUser = mssqlVersion.Spec.SecurityContext.RunAsUser + } + if m.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsGroup == nil { + m.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsGroup = mssqlVersion.Spec.SecurityContext.RunAsUser + } + } } func (m *MSSQLServer) setDefaultContainerSecurityContext(mssqlVersion *catalog.MSSQLServerVersion, podTemplate *ofst.PodTemplateSpec) { diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go index a2480347..d429042a 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go @@ -25612,14 +25612,14 @@ func schema_apimachinery_apis_kubedb_v1alpha2_CassandraSpec(ref common.Reference }, "replicas": { SchemaProps: spec.SchemaProps{ - Description: "Number of instances to deploy for a Cassandra database.", + Description: "Number of replicas for Cassandra database.", Type: []string{"integer"}, Format: "int32", }, }, "topology": { SchemaProps: spec.SchemaProps{ - Description: "rack", + Description: "Cassandra Topology for Racks", Ref: ref("kubedb.dev/apimachinery/apis/kubedb/v1alpha2.Topology"), }, }, @@ -34690,7 +34690,7 @@ func schema_apimachinery_apis_kubedb_v1alpha2_Topology(ref common.ReferenceCallb Properties: map[string]spec.Schema{ "rack": { SchemaProps: spec.SchemaProps{ - Description: "cassandra rack Structure", + Description: "cassandra rack structure", Type: []string{"array"}, Items: &spec.SchemaOrArray{ Schema: &spec.Schema{ diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/pgpool_webhook.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/pgpool_webhook.go index 5e5498da..7476ca18 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/pgpool_webhook.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/pgpool_webhook.go @@ -129,51 +129,32 @@ func (p *Pgpool) ValidateCreateOrUpdate() field.ErrorList { "use either `spec.configSecret` or `spec.initConfig`")) } - if p.Spec.ConfigSecret != nil { - secret := core.Secret{} + if p.ObjectMeta.DeletionTimestamp == nil { + apb := appcat.AppBinding{} err := DefaultClient.Get(context.TODO(), types.NamespacedName{ - Name: p.Spec.ConfigSecret.Name, - Namespace: p.Namespace, - }, &secret) + Name: p.Spec.PostgresRef.Name, + Namespace: p.Spec.PostgresRef.Namespace, + }, &apb) if err != nil { - errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"), + errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("postgresRef"), p.Name, err.Error(), )) } - _, ok := secret.Data[kubedb.PgpoolCustomConfigFile] - if !ok { - errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("configSecret"), + + backendSSL, err := p.IsBackendTLSEnabled() + if err != nil { + errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("postgresRef"), p.Name, - fmt.Sprintf("`%v` is missing", kubedb.PgpoolCustomConfigFile), + err.Error(), )) } - } - - apb := appcat.AppBinding{} - err := DefaultClient.Get(context.TODO(), types.NamespacedName{ - Name: p.Spec.PostgresRef.Name, - Namespace: p.Spec.PostgresRef.Namespace, - }, &apb) - if err != nil { - errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("postgresRef"), - p.Name, - err.Error(), - )) - } - - backendSSL, err := p.IsBackendTLSEnabled() - if err != nil { - errorList = append(errorList, field.Invalid(field.NewPath("spec").Child("postgresRef"), - p.Name, - err.Error(), - )) - } - if p.Spec.TLS == nil && backendSSL { - errorList = append(errorList, field.Required(field.NewPath("spec").Child("tls"), - "`spec.tls` must be set because backend postgres is tls enabled", - )) + if p.Spec.TLS == nil && backendSSL { + errorList = append(errorList, field.Required(field.NewPath("spec").Child("tls"), + "`spec.tls` must be set because backend postgres is tls enabled", + )) + } } if p.Spec.TLS == nil { diff --git a/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_cassandraversions.yaml b/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_cassandraversions.yaml index 11a67b70..59bdb6b2 100644 --- a/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_cassandraversions.yaml +++ b/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_cassandraversions.yaml @@ -16,7 +16,7 @@ spec: listKind: CassandraVersionList plural: cassandraversions shortNames: - - csversion + - casversion singular: cassandraversion scope: Cluster versions: diff --git a/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_memcachedversions.yaml b/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_memcachedversions.yaml index ad7910b7..4ccf401f 100644 --- a/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_memcachedversions.yaml +++ b/vendor/kubedb.dev/apimachinery/crds/catalog.kubedb.com_memcachedversions.yaml @@ -89,6 +89,17 @@ spec: - name type: object type: array + updateConstraints: + properties: + allowlist: + items: + type: string + type: array + denylist: + items: + type: string + type: array + type: object version: type: string required: diff --git a/vendor/kubedb.dev/apimachinery/crds/kubedb.com_cassandras.yaml b/vendor/kubedb.dev/apimachinery/crds/kubedb.com_cassandras.yaml index b395ba98..7c7626f9 100644 --- a/vendor/kubedb.dev/apimachinery/crds/kubedb.com_cassandras.yaml +++ b/vendor/kubedb.dev/apimachinery/crds/kubedb.com_cassandras.yaml @@ -17,7 +17,7 @@ spec: listKind: CassandraList plural: cassandras shortNames: - - cs + - cas singular: cassandra scope: Namespaced versions: @@ -74,7 +74,7 @@ spec: healthChecker: default: failureThreshold: 3 - periodSeconds: 20 + periodSeconds: 30 timeoutSeconds: 10 properties: disableWriteCheck: diff --git a/vendor/modules.txt b/vendor/modules.txt index 46c1405f..4d9e6d36 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1561,7 +1561,7 @@ kmodules.xyz/offshoot-api/api/v1 kmodules.xyz/offshoot-api/api/v1/conversion kmodules.xyz/offshoot-api/api/v2 kmodules.xyz/offshoot-api/util -# kubedb.dev/apimachinery v0.47.1-0.20240822044956-3da387889ca5 +# kubedb.dev/apimachinery v0.47.1-0.20240905094616-0f3ede79a000 ## explicit; go 1.22.1 kubedb.dev/apimachinery/apis kubedb.dev/apimachinery/apis/catalog