Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setDefaults() for pgbouncer #1022

Merged
merged 3 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apis/catalog/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions apis/catalog/v1alpha1/pgbouncer_version_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ type PgBouncerVersionSpec struct {
// Deprecated versions usable but regarded as obsolete and best avoided, typically due to having been superseded.
// +optional
Deprecated bool `json:"deprecated,omitempty"`
// SecurityContext is for the additional config for postgres DB container
// SecurityContext is for the additional config for pgbouncer DB container
// +optional
SecurityContext PostgresSecurityContext `json:"securityContext"`
SecurityContext PgBouncerSecurityContext `json:"securityContext"`
// upgrade constraints
UpgradeConstraints UpgradeConstraints `json:"upgradeConstraints,omitempty"`
}
Expand Down Expand Up @@ -90,7 +90,7 @@ type PgBouncerVersionList struct {
Items []PgBouncerVersion `json:"items,omitempty"`
}

// PgBouncerSecurityContext is the additional features for the Postgres
// PgBouncerSecurityContext is the additional features for the PgBouncer
type PgBouncerSecurityContext struct {
// RunAsUser is default UID for the DB container. It is by default 70 for postgres user.
RunAsUser *int64 `json:"runAsUser,omitempty"`
Expand Down
24 changes: 24 additions & 0 deletions apis/kubedb/v1alpha2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ limitations under the License.
package v1alpha2

import (
"context"
"fmt"

cm_api "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
appslister "k8s.io/client-go/listers/apps/v1"
apps_util "kmodules.xyz/client-go/apps/v1"
ofst "kmodules.xyz/offshoot-api/api/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func checkReplicas(lister appslister.StatefulSetNamespaceLister, selector labels.Selector, expectedItems int) (bool, string, error) {
Expand Down Expand Up @@ -106,3 +109,24 @@ func upsertStringSlice(inSlice []string, values ...string) []string {
}
return inSlice
}

func UsesAcmeIssuer(kc client.Client, ns string, issuerRef core.TypedLocalObjectReference) (bool, error) {
switch issuerRef.Kind {
case cm_api.IssuerKind:
var issuer cm_api.Issuer
err := kc.Get(context.TODO(), client.ObjectKey{Namespace: ns, Name: issuerRef.Name}, &issuer)
if err != nil {
return false, err
}
return issuer.Spec.ACME != nil, nil
case cm_api.ClusterIssuerKind:
var issuer cm_api.ClusterIssuer
err := kc.Get(context.TODO(), client.ObjectKey{Name: issuerRef.Name}, &issuer)
if err != nil {
return false, err
}
return issuer.Spec.ACME != nil, nil
default:
return false, fmt.Errorf("invalid issuer %+v", issuerRef)
}
}
5 changes: 4 additions & 1 deletion apis/kubedb/v1alpha2/pgbouncer_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (p PgBouncer) ReplicasServiceName() string {
return fmt.Sprintf("%v-replicas", p.Name)
}

func (p *PgBouncer) SetDefaults(pgBouncerVersion *catalog.PgBouncerVersion) {
func (p *PgBouncer) SetDefaults(pgBouncerVersion *catalog.PgBouncerVersion, usesAcme bool) {
if p == nil {
return
}
Expand All @@ -196,6 +196,9 @@ func (p *PgBouncer) SetDefaults(pgBouncerVersion *catalog.PgBouncerVersion) {
}

p.SetSecurityContext(pgBouncerVersion)
if p.Spec.TLS != nil {
p.SetTLSDefaults(usesAcme)
}

p.Spec.Monitor.SetDefaults()
apis.SetDefaultResourceLimits(&p.Spec.PodTemplate.Spec.Resources, DefaultResources)
Expand Down
3 changes: 2 additions & 1 deletion apis/kubedb/v1alpha2/proxysql_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p ProxySQL) StatsServiceLabels() map[string]string {
return p.ServiceLabels(StatsServiceAlias, map[string]string{LabelRole: RoleStats})
}

func (p *ProxySQL) SetDefaults() {
func (p *ProxySQL) SetDefaults(usesAcme bool) {
if p == nil {
return
}
Expand All @@ -175,6 +175,7 @@ func (p *ProxySQL) SetDefaults() {
}

p.Spec.Monitor.SetDefaults()
p.SetTLSDefaults(usesAcme)
p.SetHealthCheckerDefaults()
apis.SetDefaultResourceLimits(&p.Spec.PodTemplate.Spec.Resources, DefaultResources)
}
Expand Down