diff --git a/clickhouse/client.go b/clickhouse/client.go index 5e81195c..549d1a28 100644 --- a/clickhouse/client.go +++ b/clickhouse/client.go @@ -1,3 +1,19 @@ +/* +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 clickhouse import ( diff --git a/clickhouse/kubedb_client_builder.go b/clickhouse/kubedb_client_builder.go index 82b80269..225abd11 100644 --- a/clickhouse/kubedb_client_builder.go +++ b/clickhouse/kubedb_client_builder.go @@ -1,3 +1,19 @@ +/* +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 clickhouse import ( diff --git a/go.mod b/go.mod index c76ee6f4..95dd918d 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( k8s.io/klog/v2 v2.120.1 kmodules.xyz/client-go v0.30.1 kmodules.xyz/custom-resources v0.29.1 - kubedb.dev/apimachinery v0.46.1-0.20240611074256-e35c4320d8a0 + kubedb.dev/apimachinery v0.46.1-0.20240611134003-2a27409da656 sigs.k8s.io/controller-runtime v0.18.3 xorm.io/xorm v1.3.6 ) diff --git a/go.sum b/go.sum index 57d8cc61..040c3988 100644 --- a/go.sum +++ b/go.sum @@ -771,8 +771,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.29.4 h1:WQV2BIUIoVKKiqZNmZ4gAy367jEdwBhEl3dFCLZM1qA= kmodules.xyz/offshoot-api v0.29.4/go.mod h1:e+NQ0s4gW/YTPWBWEfdISZcmk+tlTq8IjvP5SLdqvko= -kubedb.dev/apimachinery v0.46.1-0.20240611074256-e35c4320d8a0 h1:7kfwHtlv6jdDKLYodaB+OhAbk+S+ps8eMuq9dFoZuZk= -kubedb.dev/apimachinery v0.46.1-0.20240611074256-e35c4320d8a0/go.mod h1:GSK9VlG2l34NcgK5stYfRkYTOpNBO92OMURvcGI+0lI= +kubedb.dev/apimachinery v0.46.1-0.20240611134003-2a27409da656 h1:mddRcjBjY7skieguxN/s4OVIBWXufG29KEe2TyoaHig= +kubedb.dev/apimachinery v0.46.1-0.20240611134003-2a27409da656/go.mod h1:GSK9VlG2l34NcgK5stYfRkYTOpNBO92OMURvcGI+0lI= kubeops.dev/petset v0.0.6 h1:0IbvxD9fadZfH+3iMZWzN6ZHsO0vX458JlioamwyPKQ= kubeops.dev/petset v0.0.6/go.mod h1:A15vh0r979NsvL65DTIZKWsa/NoX9VapHBAEw1ZsdYI= lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= diff --git a/mongodb/kubedb_client_builder.go b/mongodb/kubedb_client_builder.go index cc86e086..428ec0e9 100644 --- a/mongodb/kubedb_client_builder.go +++ b/mongodb/kubedb_client_builder.go @@ -24,7 +24,7 @@ import ( "time" "kubedb.dev/apimachinery/apis/kubedb" - api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2" + api "kubedb.dev/apimachinery/apis/kubedb/v1" "go.mongodb.org/mongo-driver/mongo" mgoptions "go.mongodb.org/mongo-driver/mongo/options" diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mongodb_helpers.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mongodb_helpers.go index 6d234f3d..346b4002 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mongodb_helpers.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mongodb_helpers.go @@ -689,7 +689,7 @@ func (m *MongoDB) setPodTemplateDefaultValues(podTemplate *ofstv2.PodTemplateSpe defaultResource = kubedb.DefaultResourcesCPUIntensive } - container := EnsureContainerExists(podTemplate, kubedb.MongoDBInitInstallContainerName) + container := EnsureInitContainerExists(podTemplate, kubedb.MongoDBInitInstallContainerName) m.setContainerDefaultValues(container, mgVersion, defaultResource, isArbiter...) container = EnsureContainerExists(podTemplate, kubedb.MongoDBInitInstallContainerName) diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mysql_helpers.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mysql_helpers.go index 8ea2dc26..aebbfee8 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mysql_helpers.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mysql_helpers.go @@ -271,11 +271,6 @@ func (m *MySQL) SetDefaults(myVersion *v1alpha1.MySQLVersion, topology *core_uti if m.UsesGroupReplication() || m.IsInnoDBCluster() || m.IsSemiSync() { if m.Spec.Replicas == nil { m.Spec.Replicas = pointer.Int32P(kubedb.MySQLDefaultGroupSize) - } else { - if m.Spec.Coordinator.SecurityContext == nil { - m.Spec.Coordinator.SecurityContext = &core.SecurityContext{} - } - m.assignDefaultContainerSecurityContext(myVersion, m.Spec.Coordinator.SecurityContext) } } else { if m.Spec.Replicas == nil { @@ -283,17 +278,16 @@ func (m *MySQL) SetDefaults(myVersion *v1alpha1.MySQLVersion, topology *core_uti } } + m.setDefaultContainerSecurityContext(myVersion, &m.Spec.PodTemplate) + if m.Spec.PodTemplate.Spec.ServiceAccountName == "" { m.Spec.PodTemplate.Spec.ServiceAccountName = m.OffshootName() } - m.setDefaultContainerSecurityContext(myVersion, &m.Spec.PodTemplate) + m.setDefaultContainerResourceLimits(&m.Spec.PodTemplate) m.SetTLSDefaults() m.SetHealthCheckerDefaults() - dbContainer := core_util.GetContainerByName(m.Spec.PodTemplate.Spec.Containers, kubedb.MySQLContainerName) - if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) { - apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources) - } + m.Spec.Monitor.SetDefaults() if m.Spec.Monitor != nil && m.Spec.Monitor.Prometheus != nil { if m.Spec.Monitor.Prometheus.Exporter.SecurityContext.RunAsUser == nil { @@ -388,7 +382,7 @@ func (m *MySQL) GetRouterName() string { func (m *MySQL) setDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVersion, podTemplate *ofstv2.PodTemplateSpec) { if podTemplate == nil { - return + podTemplate = &ofstv2.PodTemplateSpec{} } if podTemplate.Spec.SecurityContext == nil { @@ -397,6 +391,7 @@ func (m *MySQL) setDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVers if podTemplate.Spec.SecurityContext.FSGroup == nil { podTemplate.Spec.SecurityContext.FSGroup = myVersion.Spec.SecurityContext.RunAsUser } + dbContainer := core_util.GetContainerByName(podTemplate.Spec.Containers, kubedb.MySQLContainerName) if dbContainer == nil { dbContainer = &core.Container{ @@ -408,6 +403,32 @@ func (m *MySQL) setDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVers } m.assignDefaultContainerSecurityContext(myVersion, dbContainer.SecurityContext) podTemplate.Spec.Containers = core_util.UpsertContainer(podTemplate.Spec.Containers, *dbContainer) + + initContainer := core_util.GetContainerByName(podTemplate.Spec.InitContainers, kubedb.MySQLInitContainerName) + if initContainer == nil { + initContainer = &core.Container{ + Name: kubedb.MySQLInitContainerName, + } + } + if initContainer.SecurityContext == nil { + initContainer.SecurityContext = &core.SecurityContext{} + } + m.assignDefaultContainerSecurityContext(myVersion, initContainer.SecurityContext) + podTemplate.Spec.InitContainers = core_util.UpsertContainer(podTemplate.Spec.InitContainers, *initContainer) + + if m.IsInnoDBCluster() || m.IsSemiSync() || m.IsRemoteReplica() { + coordinatorContainer := core_util.GetContainerByName(podTemplate.Spec.Containers, kubedb.MySQLCoordinatorContainerName) + if coordinatorContainer == nil { + coordinatorContainer = &core.Container{ + Name: kubedb.MySQLCoordinatorContainerName, + } + } + if coordinatorContainer.SecurityContext == nil { + coordinatorContainer.SecurityContext = &core.SecurityContext{} + } + m.assignDefaultContainerSecurityContext(myVersion, coordinatorContainer.SecurityContext) + podTemplate.Spec.Containers = core_util.UpsertContainer(podTemplate.Spec.Containers, *coordinatorContainer) + } } func (m *MySQL) assignDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVersion, sc *core.SecurityContext) { @@ -432,3 +453,22 @@ func (m *MySQL) assignDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLV sc.SeccompProfile = secomp.DefaultSeccompProfile() } } + +func (m *MySQL) setDefaultContainerResourceLimits(podTemplate *ofstv2.PodTemplateSpec) { + dbContainer := core_util.GetContainerByName(podTemplate.Spec.Containers, kubedb.MySQLContainerName) + if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) { + apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources) + } + + initContainer := core_util.GetContainerByName(podTemplate.Spec.InitContainers, kubedb.MySQLInitContainerName) + if initContainer != nil && (initContainer.Resources.Requests == nil && initContainer.Resources.Limits == nil) { + apis.SetDefaultResourceLimits(&initContainer.Resources, kubedb.DefaultInitContainerResource) + } + + if m.IsInnoDBCluster() || m.IsSemiSync() || m.IsRemoteReplica() { + coordinatorContainer := core_util.GetContainerByName(podTemplate.Spec.Containers, kubedb.MySQLCoordinatorContainerName) + if coordinatorContainer != nil && (coordinatorContainer.Resources.Requests == nil && coordinatorContainer.Resources.Limits == nil) { + apis.SetDefaultResourceLimits(&coordinatorContainer.Resources, kubedb.CoordinatorDefaultResources) + } + } +} diff --git a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mysql_helpers.go b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mysql_helpers.go index d4eeb102..e8733ff6 100644 --- a/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mysql_helpers.go +++ b/vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/mysql_helpers.go @@ -281,12 +281,12 @@ func (m *MySQL) SetDefaults(myVersion *v1alpha1.MySQLVersion, topology *core_uti } } + m.setDefaultContainerSecurityContext(myVersion, &m.Spec.PodTemplate) + if m.Spec.PodTemplate.Spec.ServiceAccountName == "" { m.Spec.PodTemplate.Spec.ServiceAccountName = m.OffshootName() } - m.setDefaultContainerSecurityContext(myVersion, &m.Spec.PodTemplate) - m.setDefaultAffinity(&m.Spec.PodTemplate, m.OffshootSelectors(), topology) m.SetTLSDefaults() m.SetHealthCheckerDefaults() @@ -425,7 +425,7 @@ func (m *MySQL) GetRouterName() string { func (m *MySQL) setDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVersion, podTemplate *ofst.PodTemplateSpec) { if podTemplate == nil { - return + podTemplate = &ofst.PodTemplateSpec{} } if podTemplate.Spec.ContainerSecurityContext == nil { podTemplate.Spec.ContainerSecurityContext = &core.SecurityContext{} @@ -437,6 +437,18 @@ func (m *MySQL) setDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVers podTemplate.Spec.SecurityContext.FSGroup = myVersion.Spec.SecurityContext.RunAsUser } m.assignDefaultContainerSecurityContext(myVersion, podTemplate.Spec.ContainerSecurityContext) + + initContainer := core_util.GetContainerByName(podTemplate.Spec.InitContainers, kubedb.MySQLInitContainerName) + if initContainer == nil { + initContainer = &core.Container{ + Name: kubedb.MySQLInitContainerName, + } + } + if initContainer.SecurityContext == nil { + initContainer.SecurityContext = &core.SecurityContext{} + } + m.assignDefaultContainerSecurityContext(myVersion, initContainer.SecurityContext) + podTemplate.Spec.InitContainers = core_util.UpsertContainer(podTemplate.Spec.InitContainers, *initContainer) } func (m *MySQL) assignDefaultContainerSecurityContext(myVersion *v1alpha1.MySQLVersion, sc *core.SecurityContext) { diff --git a/vendor/modules.txt b/vendor/modules.txt index ca83054b..62acdb46 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1508,7 +1508,7 @@ kmodules.xyz/monitoring-agent-api/api/v1 kmodules.xyz/offshoot-api/api/v1 kmodules.xyz/offshoot-api/api/v1/conversion kmodules.xyz/offshoot-api/api/v2 -# kubedb.dev/apimachinery v0.46.1-0.20240611074256-e35c4320d8a0 +# kubedb.dev/apimachinery v0.46.1-0.20240611134003-2a27409da656 ## explicit; go 1.22.0 kubedb.dev/apimachinery/apis kubedb.dev/apimachinery/apis/catalog