Skip to content

Commit

Permalink
Pgpool backend reference change (#90)
Browse files Browse the repository at this point in the history
* Pgpool backend reference change

Signed-off-by: MobarakHsn <[email protected]>

* Pgpool backend reference change

Signed-off-by: MobarakHsn <[email protected]>

* Pgpool backend to postgresRef

Signed-off-by: MobarakHsn <[email protected]>

* Pgpool update dependency

Signed-off-by: MobarakHsn <[email protected]>

---------

Signed-off-by: MobarakHsn <[email protected]>
  • Loading branch information
MobarakHsn authored Feb 27, 2024
1 parent fffdeec commit 6da3a3e
Show file tree
Hide file tree
Showing 30 changed files with 2,084 additions and 822 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ require (
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/klog/v2 v2.110.1
kmodules.xyz/client-go v0.29.8
kmodules.xyz/client-go v0.29.9
kmodules.xyz/custom-resources v0.29.1
kubedb.dev/apimachinery v0.42.0
kubedb.dev/apimachinery v0.42.2-0.20240227074455-429a2b10fe50
sigs.k8s.io/controller-runtime v0.17.0
xorm.io/xorm v1.3.6
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,16 @@ k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6R
k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/client-go v0.29.8 h1:8Uw7zoaye0ZaY47fBVTLjDOOn6cXzLPYBNnzHj7pgH4=
kmodules.xyz/client-go v0.29.8/go.mod h1:WYM/ZC3I5/AUGHYyYYEzYHFhnSwK+tEZyGld6KpLoxI=
kmodules.xyz/client-go v0.29.9 h1:nZcKM4YzmHAAQ62EYLep1NQdhARA9uOnYOiHMRf2VVg=
kmodules.xyz/client-go v0.29.9/go.mod h1:WYM/ZC3I5/AUGHYyYYEzYHFhnSwK+tEZyGld6KpLoxI=
kmodules.xyz/custom-resources v0.29.1 h1:xiNylhs3ILRbcUhxxy306AOy9GMA4Mq7xFIptZKgal4=
kmodules.xyz/custom-resources v0.29.1/go.mod h1:829zDY1EjaxPP52h1T73LZx/vgv8Pld9/uTT/ViZTc0=
kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9H1UFRwB4=
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
kubedb.dev/apimachinery v0.42.0 h1:i+Lq2LIrdGOqBNizP83YYhLO8YvGCx4e1chKQwMG78E=
kubedb.dev/apimachinery v0.42.0/go.mod h1:SAqjTUSzUBFedESPe0HJmV+pElaCPA7tyg4OUFyWi1c=
kubedb.dev/apimachinery v0.42.2-0.20240227074455-429a2b10fe50 h1:cyVDIRYXLBss+GjVBNwh7qaWZaCn10BxRw7SUnGbcJs=
kubedb.dev/apimachinery v0.42.2-0.20240227074455-429a2b10fe50/go.mod h1:snGyLCdf0EDRjEMVxAtbObhL8lyFG/y/hNNVprYu1yE=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
Expand Down
30 changes: 15 additions & 15 deletions pgpool/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ func (o *KubeDBClientBuilder) getURL() string {

func (o *KubeDBClientBuilder) getBackendAuth() (string, string, error) {
pp := o.pgpool
var secretName string
if pp.Spec.Backend != nil {
apb := &appbinding.AppBinding{}
err := o.kc.Get(o.ctx, types.NamespacedName{
Name: pp.Spec.Backend.Name,
Namespace: pp.Namespace,
}, apb)
if err != nil {
return "", "", err
}
if apb.Spec.Secret == nil {
return "", "", fmt.Errorf("backend database auth secret not found")
}
secretName = apb.Spec.Secret.Name
if pp.Spec.PostgresRef == nil {
return "", "", fmt.Errorf("there is no postgresRef found for pgpool %s/%s", pp.Namespace, pp.Name)
}
apb := &appbinding.AppBinding{}
err := o.kc.Get(o.ctx, types.NamespacedName{
Name: pp.Spec.PostgresRef.Name,
Namespace: pp.Spec.PostgresRef.Namespace,
}, apb)
if err != nil {
return "", "", err
}
if apb.Spec.Secret == nil {
return "", "", fmt.Errorf("backend postgres auth secret unspecified for pgpool %s/%s", pp.Namespace, pp.Name)
}

var secret core.Secret
err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: pp.Namespace, Name: secretName}, &secret)
err = o.kc.Get(o.ctx, client.ObjectKey{Namespace: pp.Spec.PostgresRef.Namespace, Name: apb.Spec.Secret.Name}, &secret)
if err != nil {
return "", "", err
}
Expand Down
7 changes: 6 additions & 1 deletion vendor/kmodules.xyz/client-go/apiextensions/v1/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"context"
"time"

"github.com/pkg/errors"
api "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -29,6 +30,10 @@ import (
kutil "kmodules.xyz/client-go"
)

const (
RetryTimeout = 10 * time.Minute
)

func CreateOrUpdateCustomResourceDefinition(
ctx context.Context,
c cs.Interface,
Expand Down Expand Up @@ -70,7 +75,7 @@ func TryUpdateCustomResourceDefinition(
opts metav1.UpdateOptions,
) (result *api.CustomResourceDefinition, err error) {
attempt := 0
err = wait.PollUntilContextTimeout(ctx, kutil.RetryInterval, kutil.RetryTimeout, true, func(ctx context.Context) (bool, error) {
err = wait.PollUntilContextTimeout(ctx, kutil.RetryInterval, RetryTimeout, true, func(ctx context.Context) (bool, error) {
attempt++
cur, e2 := c.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, name, metav1.GetOptions{})
if kerr.IsNotFound(e2) {
Expand Down
47 changes: 47 additions & 0 deletions vendor/kmodules.xyz/client-go/core/v1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package v1
import (
"sort"

"kmodules.xyz/client-go/meta"

jsoniter "github.com/json-iterator/go"
"gomodules.xyz/mergo"
core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -108,6 +110,31 @@ func UpsertContainer(containers []core.Container, upsert core.Container) []core.
return append(containers, upsert)
}

func MergeContainer(container core.Container, containerTemplate core.Container) core.Container {
container.Command = containerTemplate.Command
container.Args = meta.UpsertArgumentList(container.Args, containerTemplate.Args)
container.WorkingDir = containerTemplate.WorkingDir
container.EnvFrom = containerTemplate.EnvFrom
container.Env = UpsertEnvVars(container.Env, containerTemplate.Env...)
container.Ports = UpsertContainerPorts(container.Ports, containerTemplate.Ports...)
container.Resources = containerTemplate.Resources
container.ResizePolicy = containerTemplate.ResizePolicy
container.RestartPolicy = containerTemplate.RestartPolicy
container.VolumeMounts = UpsertVolumeMount(container.VolumeMounts, containerTemplate.VolumeMounts...)
container.VolumeDevices = containerTemplate.VolumeDevices
container.LivenessProbe = containerTemplate.LivenessProbe
container.ReadinessProbe = containerTemplate.ReadinessProbe
container.StartupProbe = containerTemplate.StartupProbe
container.Lifecycle = containerTemplate.Lifecycle
container.TerminationMessagePath = containerTemplate.TerminationMessagePath
container.TerminationMessagePolicy = containerTemplate.TerminationMessagePolicy
container.ImagePullPolicy = containerTemplate.ImagePullPolicy
container.SecurityContext = containerTemplate.SecurityContext
container.StdinOnce = containerTemplate.StdinOnce
container.TTY = containerTemplate.TTY
return container
}

func UpsertContainers(containers []core.Container, addons []core.Container) []core.Container {
out := containers
for _, c := range addons {
Expand Down Expand Up @@ -264,6 +291,26 @@ func EnsureVolumeMountDeletedByPath(mounts []core.VolumeMount, mountPath string)
return mounts
}

func UpsertContainerPorts(ports []core.ContainerPort, np ...core.ContainerPort) []core.ContainerPort {
upsert := func(p core.ContainerPort) {
for i, port := range ports {
if port.Name == p.Name {
err := mergo.Merge(&ports[i], p, mergo.WithOverride)
if err != nil {
panic(err)
}
return
}
}
ports = append(ports, p)
}

for _, port := range np {
upsert(port)
}
return ports
}

func GetEnvByName(envs []core.EnvVar, name string) *core.EnvVar {
for i := range envs {
if envs[i].Name == name {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,20 @@ func (k *ConnectCluster) setDefaultInitContainerSecurityContext(podTemplate *ofs
}

initContainer := coreutil.GetContainerByName(podTemplate.Spec.InitContainers, strings.ToLower(connectorVersion.Spec.Type))

if initContainer == nil {
initContainer = &core.Container{
Name: strings.ToLower(connectorVersion.Spec.Type),
}
podTemplate.Spec.InitContainers = coreutil.UpsertContainer(podTemplate.Spec.InitContainers, *initContainer)
}

if initContainer != nil && (initContainer.Resources.Requests == nil && initContainer.Resources.Limits == nil) {
apis.SetDefaultResourceLimits(&initContainer.Resources, api.DefaultInitContainerResource)
}
if initContainer.SecurityContext == nil {
initContainer.SecurityContext = &core.SecurityContext{}
}
k.assignDefaultInitContainerSecurityContext(connectorVersion, initContainer.SecurityContext)
podTemplate.Spec.InitContainers = coreutil.UpsertContainer(podTemplate.Spec.InitContainers, *initContainer)
}
}

Expand All @@ -339,12 +342,12 @@ func (k *ConnectCluster) setDefaultContainerSecurityContext(kfVersion *catalog.K
container = &core.Container{
Name: ConnectClusterContainerName,
}
podTemplate.Spec.Containers = append(podTemplate.Spec.Containers, *container)
}
if container.SecurityContext == nil {
container.SecurityContext = &core.SecurityContext{}
}
k.assignDefaultContainerSecurityContext(kfVersion, container.SecurityContext)
podTemplate.Spec.Containers = coreutil.UpsertContainer(podTemplate.Spec.Containers, *container)
}

func (k *ConnectCluster) assignDefaultInitContainerSecurityContext(connectorVersion *catalog.KafkaConnectorVersion, sc *core.SecurityContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ type ConnectorStatus struct {
Conditions []kmapi.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:validation:Enum=Pending;Running;Paused;Stopped;Unknown
// +kubebuilder:validation:Enum=Pending;Unassigned;Running;Paused;Failed;Restarting;Stopped;Destroyed;Unknown
type ConnectorPhase string

const (
ConnectorPhasePending ConnectorPhase = "Pending"
ConnectorPhaseRunning ConnectorPhase = "Running"
ConnectorPhasePaused ConnectorPhase = "Paused"
ConnectorPhaseStopped ConnectorPhase = "Stopped"
ConnectorPhaseUnknown ConnectorPhase = "Unknown"
ConnectorPhasePending ConnectorPhase = "Pending"
ConnectorPhaseUnassigned ConnectorPhase = "Unassigned"
ConnectorPhaseRunning ConnectorPhase = "Running"
ConnectorPhasePaused ConnectorPhase = "Paused"
ConnectorPhaseFailed ConnectorPhase = "Failed"
ConnectorPhaseRestarting ConnectorPhase = "Restarting"
ConnectorPhaseStopped ConnectorPhase = "Stopped"
ConnectorPhaseDestroyed ConnectorPhase = "Destroyed"
ConnectorPhaseUnknown ConnectorPhase = "Unknown"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
58 changes: 27 additions & 31 deletions vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,8 @@ const (
SolrInitContainerName = "init-solr"
SolrAdmin = "admin"
SecurityJSON = "security.json"
SolrZkDigest = "zk-digest"
SolrZkReadonlyDigest = "zk-digest-readonly"

SolrVolumeDefaultConfig = "default-config"
SolrVolumeCustomConfig = "custom-config"
Expand Down Expand Up @@ -791,9 +793,11 @@ const (
SolrCloudDistribUpdateConnTimeoutKey = "distribUpdateConnTimeout"
SolrCloudDistribUpdateConnTimeoutValue = 60000
SolrCloudZKCredentialProviderKey = "zkCredentialsProvider"
SolrCloudZKCredentialProviderValue = "org.apache.solr.common.cloud.DefaultZkCredentialsProvider"
SolrCloudZKCredentialProviderValue = "org.apache.solr.common.cloud.DigestZkCredentialsProvider"
SolrCloudZKAclProviderKey = "zkACLProvider"
SolrCloudZKAclProviderValue = "org.apache.solr.common.cloud.DefaultZkACLProvider"
SolrCloudZKAclProviderValue = "org.apache.solr.common.cloud.DigestZkACLProvider"
SolrCloudZKCredentialsInjectorKey = "zkCredentialsInjector"
SolrCloudZKCredentialsInjectorValue = "org.apache.solr.common.cloud.VMParamsZkCredentialsInjector"

ShardHandlerFactorySocketTimeoutKey = "socketTimeout"
ShardHandlerFactorySocketTimeoutValue = 600000
Expand Down Expand Up @@ -835,17 +839,19 @@ const (
DruidMainConfigDir = "/opt/druid/conf"
DruidCustomConfigDir = "/tmp/config/custom-config"

DruidVolumeConfigCommon = "common-config-volume"
DruidVolumeConfigNodes = "nodetype-config-volume"
DruidConfigFileNameCommon = "common.runtime.properties"
DruidConfigFileNameJVM = "jvm.config"
DruidVolumeConfigFileNodes = "runtime.properties"
DruidConfigFileNameCoordinators = "coordinators.properties"
DruidConfigFileNameHistoricals = "historicals.properties"
DruidConfigFileNameMiddleManagers = "middleManagers.properties"
DruidConfigFileNameBrokers = "brokers.properties"
DruidConfigFileNameRouters = "routers.properties"
DruidVolumeMySQLMetadataStorage = "mysql-metadata-storage"
DruidVolumeCommonConfig = "common-config-volume"
DruidCommonConfigFile = "common.runtime.properties"
DruidCoordinatorsJVMConfigFile = "coordinators.jvm.config"
DruidHistoricalsJVMConfigFile = "historicals.jvm.config"
DruidBrokersJVMConfigFile = "brokers.jvm.config"
DruidMiddleManagersJVMConfigFile = "middleManagers.jvm.config"
DruidRoutersJVMConfigFile = "routers.jvm.config"
DruidCoordinatorsConfigFile = "coordinators.properties"
DruidHistoricalsConfigFile = "historicals.properties"
DruidMiddleManagersConfigFile = "middleManagers.properties"
DruidBrokersConfigFile = "brokers.properties"
DruidRoutersConfigFile = "routers.properties"
DruidVolumeMySQLMetadataStorage = "mysql-metadata-storage"

DruidContainerName = "druid"
DruidInitContainerName = "init-druid"
Expand All @@ -856,6 +862,13 @@ const (
EnvDruidZKServicePassword = "DRUID_ZK_SERVICE_PASSWORD"
EnvDruidCoordinatorAsOverlord = "DRUID_COORDINATOR_AS_OVERLORD"

DruidPortCoordinators = 8081
DruidPortOverlords = 8090
DruidPortHistoricals = 8083
DruidPortMiddleManagers = 8091
DruidPortBrokers = 8082
DruidPortRouters = 8888

// Common Runtime Configurations Properties
// ZooKeeperSpec
DruidZKServiceHost = "druid.zk.service.host"
Expand Down Expand Up @@ -927,8 +940,7 @@ const (
DruidExtensionPostgreSQLMetadataStorage = "postgresql-metadata-storage"
DruidExtensionBasicSecurity = "druid-basic-security"
DruidExtensionMultiStageQuery = "druid-multi-stage-query"

DruidService = "druid.service"
DruidService = "druid.service"

/// Coordinators Configurations
DruidCoordinatorStartDelay = "druid.coordinator.startDelay"
Expand Down Expand Up @@ -1001,22 +1013,6 @@ const (
DruidHealthDataOne = "1"
)

type DruidMetadataStorageType string

const (
DruidMetadataStorageMySQL DruidMetadataStorageType = "MySQL"
DruidMetadataStoragePostgreSQL DruidMetadataStorageType = "PostgreSQL"
)

type DruidDeepStorageType string

const (
DruidDeepStorageS3 DruidDeepStorageType = "s3"
DruidDeepStorageGoogle DruidDeepStorageType = "google"
DruidDeepStorageAzure DruidDeepStorageType = "azure"
DruidDeepStorageHDFS DruidDeepStorageType = "hdfs"
)

const (
RabbitMQAMQPPort = 5672
RabbitMQPeerDiscoveryPort = 4369
Expand Down
Loading

0 comments on commit 6da3a3e

Please sign in to comment.