Skip to content

Commit

Permalink
convert mongodb to v1 api
Browse files Browse the repository at this point in the history
Signed-off-by: sayedppqq <[email protected]>
  • Loading branch information
sayedppqq committed Jun 12, 2024
1 parent 39d546b commit f23b3cf
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 20 deletions.
16 changes: 16 additions & 0 deletions clickhouse/client.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
16 changes: 16 additions & 0 deletions clickhouse/kubedb_client_builder.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion mongodb/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
62 changes: 51 additions & 11 deletions vendor/kubedb.dev/apimachinery/apis/kubedb/v1/mysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,29 +271,23 @@ 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 {
m.Spec.Replicas = pointer.Int32P(1)
}
}

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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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{
Expand All @@ -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) {
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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{}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f23b3cf

Please sign in to comment.