Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
36 changes: 36 additions & 0 deletions config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3954,6 +3954,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -14783,6 +14795,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -23229,6 +23253,18 @@ spec:
type: object
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down
36 changes: 36 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -15670,6 +15682,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -24116,6 +24140,18 @@ spec:
type: object
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down
12 changes: 12 additions & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ spec:
# rack: rack-22
# internalTrafficPolicy: Local
# externalTrafficPolicy: Local
# externalDNS:
# prefix: "service-name"
# domain: "mongo.example.com"
# ttl: 300
resources:
limits:
cpu: "600m"
Expand Down Expand Up @@ -573,6 +577,10 @@ spec:
# rack: rack-22
# internalTrafficPolicy: Local
# externalTrafficPolicy: Local
# externalDNS:
# prefix: "service-name"
# domain: "mongo.example.com"
# ttl: 300
resources:
limits:
cpu: "600m"
Expand Down Expand Up @@ -698,6 +706,10 @@ spec:
# nodePort: 32017
# internalTrafficPolicy: Local
# externalTrafficPolicy: Local
# externalDNS:
# prefix: "service-name"
# domain: "mongo.example.com"
# ttl: 300
# hostAliases:
# - ip: "10.10.0.2"
# hostnames:
Expand Down
36 changes: 36 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -15670,6 +15682,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -24116,6 +24140,18 @@ spec:
type: object
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down
36 changes: 36 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4841,6 +4841,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -15670,6 +15682,18 @@ spec:
type: boolean
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down Expand Up @@ -24116,6 +24140,18 @@ spec:
type: object
exposeType:
type: string
externalDNS:
properties:
domain:
type: string
prefix:
type: string
ttl:
minimum: 0
type: integer
required:
- domain
type: object
externalTrafficPolicy:
type: string
internalTrafficPolicy:
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/psmdb/v1/psmdb_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ func (cr *PerconaServerMongoDB) CheckNSetDefaults(ctx context.Context, platform
if len(cr.Spec.Sharding.Mongos.ServiceAccountName) == 0 && cr.CompareVersion("1.16.0") >= 0 {
cr.Spec.Sharding.Mongos.ServiceAccountName = WorkloadSA
}

if dns := cr.Spec.Sharding.Mongos.Expose.ExternalDNS; dns != nil {
if dns.Domain == "" {
return errors.New("externalDNS requires domain for mongos")
}
if dns.Prefix == "" {
dns.Prefix = cr.Name
}
}
}

if mongos := cr.Spec.Sharding.Mongos; mongos != nil && cr.CompareVersion("1.18.0") >= 0 && cr.Status.State == AppStateInit {
Expand Down Expand Up @@ -720,6 +729,15 @@ func (rs *ReplsetSpec) SetDefaults(platform version.Platform, cr *PerconaServerM
}
}

if dns := rs.Expose.ExternalDNS; dns != nil {
if dns.Domain == "" {
return fmt.Errorf("externalDNS requires domain for replset %s", rs.Name)
}
if dns.Prefix == "" {
dns.Prefix = cr.Name
}
}

if cr.CompareVersion("1.18.0") >= 0 && cr.Status.State == AppStateInit {
if rs.Expose.DeprecatedExposeType != "" {
log.Info("Field `.expose.exposeType` was deprecated in 1.18.0. Consider using `.expose.type` instead", "cluster", cr.Name, "namespace", cr.Namespace, "replset", rs.Name)
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/psmdb/v1/psmdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,16 @@ type Expose struct {

InternalTrafficPolicy *corev1.ServiceInternalTrafficPolicy `json:"internalTrafficPolicy,omitempty"`
ExternalTrafficPolicy corev1.ServiceExternalTrafficPolicy `json:"externalTrafficPolicy,omitempty"`

ExternalDNS *ExternalDNSConfig `json:"externalDNS,omitempty"`
}

type ExternalDNSConfig struct {
Prefix string `json:"prefix,omitempty"`
// +kubebuilder:validation:Required
Domain string `json:"domain"`
Comment thread
myJamong marked this conversation as resolved.
// +kubebuilder:validation:Minimum=0
TTL int `json:"ttl,omitempty"`
}

func (e *Expose) SaveOldMeta() bool {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/psmdb/v1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions pkg/controller/perconaservermongodb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"

api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1"
"github.com/percona/percona-server-mongodb-operator/pkg/mcs"
Expand All @@ -28,7 +29,13 @@ func (r *ReconcilePerconaServerMongoDB) reconcileServices(ctx context.Context, c
}

func (r *ReconcilePerconaServerMongoDB) reconcileReplsetServices(ctx context.Context, cr *api.PerconaServerMongoDB, repls []*api.ReplsetSpec) error {
log := logf.FromContext(ctx)

for _, rs := range repls {
if rs.Expose.ExternalDNS != nil && !rs.Expose.Enabled {
log.Info("externalDNS is configured but expose is not enabled, skipping DNS annotations", "replset", rs.Name)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this get logged on every reconciliation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayankshah1607
You're right, this fires every reconcile. The log prints about every ~11s (default reconcile interval) and it is quite noisy.

Let me change it back to just silently skip when expose is disabled.
Thanks for catching this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the logging parts.
abd5cfa


// Create headless service
service := psmdb.Service(cr, rs)
if err := setControllerReference(cr, service, r.scheme); err != nil {
Expand Down
20 changes: 19 additions & 1 deletion pkg/psmdb/mongos.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,25 @@ func MongosService(cr *api.PerconaServerMongoDB, name string) corev1.Service {
}

if cr.Spec.Sharding.Mongos != nil {
svc.Annotations = cr.Spec.Sharding.Mongos.Expose.ServiceAnnotations
annotations := make(map[string]string)
for k, v := range cr.Spec.Sharding.Mongos.Expose.ServiceAnnotations {
annotations[k] = v
}

if dns := cr.Spec.Sharding.Mongos.Expose.ExternalDNS; dns != nil {
var hostname string
if cr.Spec.Sharding.Mongos.Expose.ServicePerPod {
hostname = BuildDNSHostname(dns, "mongos", name)
} else {
hostname = BuildDNSHostnameWithoutIndex(dns, "mongos")
}
annotations["external-dns.alpha.kubernetes.io/hostname"] = hostname
if dns.TTL > 0 {
annotations["external-dns.alpha.kubernetes.io/ttl"] = strconv.Itoa(dns.TTL)
}
}

svc.Annotations = annotations
for k, v := range cr.Spec.Sharding.Mongos.Expose.ServiceLabels {
if _, ok := svc.Labels[k]; !ok {
svc.Labels[k] = v
Expand Down
Loading
Loading