diff --git a/apis/config/v1alpha1/db2_hadr_config_types.go b/apis/config/v1alpha1/db2_hadr_config_types.go new file mode 100644 index 0000000000..02a10e8fb4 --- /dev/null +++ b/apis/config/v1alpha1/db2_hadr_config_types.go @@ -0,0 +1,49 @@ +/* +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 v1alpha1 + +import ( + core "k8s.io/api/core/v1" + ofst "kmodules.xyz/offshoot-api/api/v1" +) + +type DB2HADRSpec struct { + Primary int `yaml:"primary,omitempty"` + Standby int `yaml:"standby,omitempty"` + //+optional + ConfigSecret core.LocalObjectReference `yaml:"configSecret,omitempty"` + // ServiceTemplates is an optional configuration for services used to expose database + // +optional + ServiceTemplates []NamedServiceTemplateSpec `yaml:"serviceTemplates,omitempty"` +} + +// +kubebuilder:validation:Enum=primary;standby +type ServiceAlias string + +const ( + PrimaryServiceAlias ServiceAlias = "primary" + StandbyServiceAlias ServiceAlias = "standby" +) + +type NamedServiceTemplateSpec struct { + // Alias represents the identifier of the service. + Alias ServiceAlias `yaml:"alias"` + + // ServiceTemplate is an optional configuration for a service used to expose database + // +optional + ofst.ServiceTemplateSpec `yaml:",inline,omitempty"` +} diff --git a/apis/config/v1alpha1/openapi_generated.go b/apis/config/v1alpha1/openapi_generated.go index 39fdf96426..af0bb4719e 100644 --- a/apis/config/v1alpha1/openapi_generated.go +++ b/apis/config/v1alpha1/openapi_generated.go @@ -512,8 +512,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "kmodules.xyz/offshoot-api/api/v1.ServiceTemplateSpec": schema_kmodulesxyz_offshoot_api_api_v1_ServiceTemplateSpec(ref), "kmodules.xyz/offshoot-api/api/v1.Volume": schema_kmodulesxyz_offshoot_api_api_v1_Volume(ref), "kmodules.xyz/offshoot-api/api/v1.VolumeSource": schema_kmodulesxyz_offshoot_api_api_v1_VolumeSource(ref), + "kubedb.dev/apimachinery/apis/config/v1alpha1.DB2HADRSpec": schema_apimachinery_apis_config_v1alpha1_DB2HADRSpec(ref), "kubedb.dev/apimachinery/apis/config/v1alpha1.GaleraArbitratorConfiguration": schema_apimachinery_apis_config_v1alpha1_GaleraArbitratorConfiguration(ref), "kubedb.dev/apimachinery/apis/config/v1alpha1.MongoDBConfiguration": schema_apimachinery_apis_config_v1alpha1_MongoDBConfiguration(ref), + "kubedb.dev/apimachinery/apis/config/v1alpha1.NamedServiceTemplateSpec": schema_apimachinery_apis_config_v1alpha1_NamedServiceTemplateSpec(ref), "kubedb.dev/apimachinery/apis/config/v1alpha1.RedisConfiguration": schema_apimachinery_apis_config_v1alpha1_RedisConfiguration(ref), "kubedb.dev/apimachinery/apis/config/v1alpha1.Restriction": schema_apimachinery_apis_config_v1alpha1_Restriction(ref), "kubedb.dev/apimachinery/apis/config/v1alpha1.SinglestoreConfiguration": schema_apimachinery_apis_config_v1alpha1_SinglestoreConfiguration(ref), @@ -26453,6 +26455,55 @@ func schema_kmodulesxyz_offshoot_api_api_v1_VolumeSource(ref common.ReferenceCal } } +func schema_apimachinery_apis_config_v1alpha1_DB2HADRSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Primary": { + SchemaProps: spec.SchemaProps{ + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "Standby": { + SchemaProps: spec.SchemaProps{ + Default: 0, + Type: []string{"integer"}, + Format: "int32", + }, + }, + "ConfigSecret": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/api/core/v1.LocalObjectReference"), + }, + }, + "ServiceTemplates": { + SchemaProps: spec.SchemaProps{ + Description: "ServiceTemplates is an optional configuration for services used to expose database", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("kubedb.dev/apimachinery/apis/config/v1alpha1.NamedServiceTemplateSpec"), + }, + }, + }, + }, + }, + }, + Required: []string{"Primary", "Standby"}, + }, + }, + Dependencies: []string{ + "k8s.io/api/core/v1.LocalObjectReference", "kubedb.dev/apimachinery/apis/config/v1alpha1.NamedServiceTemplateSpec"}, + } +} + func schema_apimachinery_apis_config_v1alpha1_GaleraArbitratorConfiguration(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -26569,6 +26620,36 @@ func schema_apimachinery_apis_config_v1alpha1_MongoDBConfiguration(ref common.Re } } +func schema_apimachinery_apis_config_v1alpha1_NamedServiceTemplateSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Alias": { + SchemaProps: spec.SchemaProps{ + Description: "Alias represents the identifier of the service.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "ServiceTemplateSpec": { + SchemaProps: spec.SchemaProps{ + Description: "ServiceTemplate is an optional configuration for a service used to expose database", + Default: map[string]interface{}{}, + Ref: ref("kmodules.xyz/offshoot-api/api/v1.ServiceTemplateSpec"), + }, + }, + }, + Required: []string{"Alias"}, + }, + }, + Dependencies: []string{ + "kmodules.xyz/offshoot-api/api/v1.ServiceTemplateSpec"}, + } +} + func schema_apimachinery_apis_config_v1alpha1_RedisConfiguration(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/apis/config/v1alpha1/zz_generated.deepcopy.go b/apis/config/v1alpha1/zz_generated.deepcopy.go index 44a309d04d..fff8ee3172 100644 --- a/apis/config/v1alpha1/zz_generated.deepcopy.go +++ b/apis/config/v1alpha1/zz_generated.deepcopy.go @@ -26,6 +26,30 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DB2HADRSpec) DeepCopyInto(out *DB2HADRSpec) { + *out = *in + out.ConfigSecret = in.ConfigSecret + if in.ServiceTemplates != nil { + in, out := &in.ServiceTemplates, &out.ServiceTemplates + *out = make([]NamedServiceTemplateSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DB2HADRSpec. +func (in *DB2HADRSpec) DeepCopy() *DB2HADRSpec { + if in == nil { + return nil + } + out := new(DB2HADRSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GaleraArbitratorConfiguration) DeepCopyInto(out *GaleraArbitratorConfiguration) { *out = *in @@ -139,6 +163,23 @@ func (in *MongoDBConfiguration) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NamedServiceTemplateSpec) DeepCopyInto(out *NamedServiceTemplateSpec) { + *out = *in + in.ServiceTemplateSpec.DeepCopyInto(&out.ServiceTemplateSpec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamedServiceTemplateSpec. +func (in *NamedServiceTemplateSpec) DeepCopy() *NamedServiceTemplateSpec { + if in == nil { + return nil + } + out := new(NamedServiceTemplateSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RedisConfiguration) DeepCopyInto(out *RedisConfiguration) { *out = *in diff --git a/apis/kubedb/constants.go b/apis/kubedb/constants.go index e010144ad2..71567cfa45 100644 --- a/apis/kubedb/constants.go +++ b/apis/kubedb/constants.go @@ -2205,9 +2205,9 @@ const ( DB2DatabaseRoleKey = "db2.db/role" DB2DatabaseRoleObserver = "observer" DB2DatabaseRoleInstance = "instance" - DB2EnvUserName = "SYS_USER" + DB2EnvUserName = "db2inst1" DB2EnvPassword = "DB2_PWD" - DB2EnvOracleSID = "DB2_SID" + DB2EnvSID = "DB2_SID" DB2EnvDataDir = "DB2DATA" ) diff --git a/apis/kubedb/v1alpha2/db2_helpers.go b/apis/kubedb/v1alpha2/db2_helpers.go index 7d32c6470d..7d5974399a 100644 --- a/apis/kubedb/v1alpha2/db2_helpers.go +++ b/apis/kubedb/v1alpha2/db2_helpers.go @@ -131,6 +131,10 @@ func (d *DB2) ResourceSingular() string { return ResourceSingularDB2 } +func (d *DB2) ServiceAccountName() string { + return d.OffshootName() +} + func (d *DB2) SetDefaults(kc client.Client) { if d.Spec.DeletionPolicy == "" { d.Spec.DeletionPolicy = DeletionPolicyDelete diff --git a/apis/kubedb/v1alpha2/db2_types.go b/apis/kubedb/v1alpha2/db2_types.go index d7c3e2b53a..34dba58f49 100644 --- a/apis/kubedb/v1alpha2/db2_types.go +++ b/apis/kubedb/v1alpha2/db2_types.go @@ -85,6 +85,10 @@ type DB2Spec struct { // +optional // +kubebuilder:default={periodSeconds: 10, timeoutSeconds: 10, failureThreshold: 3} HealthChecker kmapi.HealthCheckSpec `json:"healthChecker"` + + // HADR configuration for DB2 + // +optional + HADRConfig *core.LocalObjectReference `json:"hadrConfig,omitempty"` } // DB2Status defines the observed state of DB2. diff --git a/apis/kubedb/v1alpha2/openapi_generated.go b/apis/kubedb/v1alpha2/openapi_generated.go index 15a1b4213a..e8539fb0c3 100644 --- a/apis/kubedb/v1alpha2/openapi_generated.go +++ b/apis/kubedb/v1alpha2/openapi_generated.go @@ -28139,11 +28139,17 @@ func schema_apimachinery_apis_kubedb_v1alpha2_DB2Spec(ref common.ReferenceCallba Ref: ref("kmodules.xyz/client-go/api/v1.HealthCheckSpec"), }, }, + "hadrConfig": { + SchemaProps: spec.SchemaProps{ + Description: "HADR configuration for DB2", + Ref: ref("k8s.io/api/core/v1.LocalObjectReference"), + }, + }, }, }, }, Dependencies: []string{ - "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "kmodules.xyz/client-go/api/v1.HealthCheckSpec", "kmodules.xyz/offshoot-api/api/v2.PodTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.NamedServiceTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.SecretReference"}, + "k8s.io/api/core/v1.LocalObjectReference", "k8s.io/api/core/v1.PersistentVolumeClaimSpec", "kmodules.xyz/client-go/api/v1.HealthCheckSpec", "kmodules.xyz/offshoot-api/api/v2.PodTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.NamedServiceTemplateSpec", "kubedb.dev/apimachinery/apis/kubedb/v1alpha2.SecretReference"}, } } diff --git a/apis/kubedb/v1alpha2/zz_generated.deepcopy.go b/apis/kubedb/v1alpha2/zz_generated.deepcopy.go index d2b2ba0374..e387a58113 100644 --- a/apis/kubedb/v1alpha2/zz_generated.deepcopy.go +++ b/apis/kubedb/v1alpha2/zz_generated.deepcopy.go @@ -973,6 +973,11 @@ func (in *DB2Spec) DeepCopyInto(out *DB2Spec) { } } in.HealthChecker.DeepCopyInto(&out.HealthChecker) + if in.HADRConfig != nil { + in, out := &in.HADRConfig, &out.HADRConfig + *out = new(corev1.LocalObjectReference) + **out = **in + } return } diff --git a/crds/kubedb.com_db2s.yaml b/crds/kubedb.com_db2s.yaml index 95cc784b81..79d711a68a 100644 --- a/crds/kubedb.com_db2s.yaml +++ b/crds/kubedb.com_db2s.yaml @@ -77,6 +77,13 @@ spec: - WipeOut - DoNotTerminate type: string + hadrConfig: + properties: + name: + default: "" + type: string + type: object + x-kubernetes-map-type: atomic healthChecker: default: failureThreshold: 3