Skip to content

Commit

Permalink
Add support for Pod dnsPolicy and dnsConfig (#615)
Browse files Browse the repository at this point in the history
* Add .spec.dns.policy and .spec.dns.config

* Update bundle manifests

* Set defaults when fields are cleared

* Update utils.go
  • Loading branch information
kabicin authored Aug 27, 2024
1 parent 3c5cb1c commit 36ee3ed
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 14 deletions.
32 changes: 31 additions & 1 deletion api/v1/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ type RuntimeComponentSpec struct {
// Tolerations to be added to application pods. Tolerations allow the scheduler to schedule pods on nodes with matching taints.
// +operator-sdk:csv:customresourcedefinitions:order=28,type=spec,displayName="Tolerations"
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// DNS settings for the pod.
// +operator-sdk:csv:customresourcedefinitions:order=29,type=spec,displayName="DNS"
DNS *RuntimeComponentDNS `json:"dns,omitempty"`
}

// Defines the DNS
type RuntimeComponentDNS struct {
// The DNS Policy for the application pod.
// +operator-sdk:csv:customresourcedefinitions:order=1,type=spec,displayName="DNS Policy"
DNSPolicy *corev1.DNSPolicy `json:"policy,omitempty"`

// The DNS Config for the application pod.
// +operator-sdk:csv:customresourcedefinitions:order=2,type=spec,displayName="DNS Config"
PodDNSConfig *corev1.PodDNSConfig `json:"config,omitempty"`
}

// Defines the topology spread constraints
Expand All @@ -166,7 +181,7 @@ type RuntimeComponentTopologySpreadConstraints struct {
Constraints *[]corev1.TopologySpreadConstraint `json:"constraints,omitempty"`

// Whether the operator should disable its default set of TopologySpreadConstraints. Defaults to false.
// +operator-sdk:csv:customresourcedefinitions:order=1,type=spec,displayName="Disable Operator Defaults",xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
// +operator-sdk:csv:customresourcedefinitions:order=2,type=spec,displayName="Disable Operator Defaults",xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch"
DisableOperatorDefaults *bool `json:"disableOperatorDefaults,omitempty"`
}

Expand Down Expand Up @@ -959,6 +974,21 @@ func (cr *RuntimeComponent) GetTopologySpreadConstraints() common.BaseComponentT
return cr.Spec.TopologySpreadConstraints
}

func (cr *RuntimeComponent) GetDNS() common.BaseComponentDNS {
if cr.Spec.DNS == nil {
return nil
}
return cr.Spec.DNS
}

func (d *RuntimeComponentDNS) GetPolicy() *corev1.DNSPolicy {
return d.DNSPolicy
}

func (d *RuntimeComponentDNS) GetConfig() *corev1.PodDNSConfig {
return d.PodDNSConfig
}

func (cr *RuntimeComponentTopologySpreadConstraints) GetConstraints() *[]corev1.TopologySpreadConstraint {
if cr.Constraints == nil {
return nil
Expand Down
30 changes: 30 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

44 changes: 44 additions & 0 deletions bundle/manifests/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,50 @@ spec:
description: Disable information about services being injected into
the application pod's environment variables. Default to false.
type: boolean
dns:
description: DNS settings for the pod.
properties:
config:
description: The DNS Config for the application pod.
properties:
nameservers:
description: |-
A list of DNS name server IP addresses.
This will be appended to the base nameservers generated from DNSPolicy.
Duplicated nameservers will be removed.
items:
type: string
type: array
options:
description: |-
A list of DNS resolver options.
This will be merged with the base options generated from DNSPolicy.
Duplicated entries will be removed. Resolution options given in Options
will override those that appear in the base DNSPolicy.
items:
description: PodDNSConfigOption defines DNS resolver options
of a pod.
properties:
name:
description: Required.
type: string
value:
type: string
type: object
type: array
searches:
description: |-
A list of DNS search domains for host-name lookup.
This will be appended to the base search paths generated from DNSPolicy.
Duplicated search paths will be removed.
items:
type: string
type: array
type: object
policy:
description: The DNS Policy for the application pod.
type: string
type: object
env:
description: An array of environment variables for the application
container.
Expand Down
21 changes: 15 additions & 6 deletions bundle/manifests/runtime-component.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ spec:
path: autoscaling.maxReplicas
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: The DNS Policy for the application pod.
displayName: DNS Policy
path: dns.policy
- description: Probe to determine successful initialization. If specified, other
probes are not executed until this completes successfully.
displayName: Startup Probe
Expand All @@ -151,12 +154,6 @@ spec:
- description: The list of TopologySpreadConstraints for the application pod.
displayName: Constraints
path: topologySpreadConstraints.constraints
- description: Whether the operator should disable its default set of TopologySpreadConstraints.
Defaults to false.
displayName: Disable Operator Defaults
path: topologySpreadConstraints.disableOperatorDefaults
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: Name of the application. Defaults to the name of this custom
resource.
displayName: Application Name
Expand All @@ -168,6 +165,9 @@ spec:
path: autoscaling.minReplicas
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: The DNS Config for the application pod.
displayName: DNS Config
path: dns.config
- description: Periodic probe of container service readiness. Container will
be removed from service endpoints if the probe fails.
displayName: Readiness Probe
Expand All @@ -178,6 +178,12 @@ spec:
path: serviceAccount.name
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:text
- description: Whether the operator should disable its default set of TopologySpreadConstraints.
Defaults to false.
displayName: Disable Operator Defaults
path: topologySpreadConstraints.disableOperatorDefaults
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: Version of the application.
displayName: Application Version
path: applicationVersion
Expand Down Expand Up @@ -386,6 +392,9 @@ spec:
the scheduler to schedule pods on nodes with matching taints.
displayName: Tolerations
path: tolerations
- description: DNS settings for the pod.
displayName: DNS
path: dns
- description: Labels to set on ServiceMonitor.
displayName: Monitoring Labels
path: monitoring.labels
Expand Down
6 changes: 6 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ type BaseComponentTopologySpreadConstraints interface {
GetDisableOperatorDefaults() *bool
}

type BaseComponentDNS interface {
GetPolicy() *corev1.DNSPolicy
GetConfig() *corev1.PodDNSConfig
}

// BaseComponent represents basic kubernetes application
type BaseComponent interface {
GetApplicationImage() string
Expand Down Expand Up @@ -235,4 +240,5 @@ type BaseComponent interface {
GetManageTLS() *bool
GetDisableServiceLinks() *bool
GetTolerations() []corev1.Toleration
GetDNS() BaseComponentDNS
}
44 changes: 44 additions & 0 deletions config/crd/bases/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,50 @@ spec:
description: Disable information about services being injected into
the application pod's environment variables. Default to false.
type: boolean
dns:
description: DNS settings for the pod.
properties:
config:
description: The DNS Config for the application pod.
properties:
nameservers:
description: |-
A list of DNS name server IP addresses.
This will be appended to the base nameservers generated from DNSPolicy.
Duplicated nameservers will be removed.
items:
type: string
type: array
options:
description: |-
A list of DNS resolver options.
This will be merged with the base options generated from DNSPolicy.
Duplicated entries will be removed. Resolution options given in Options
will override those that appear in the base DNSPolicy.
items:
description: PodDNSConfigOption defines DNS resolver options
of a pod.
properties:
name:
description: Required.
type: string
value:
type: string
type: object
type: array
searches:
description: |-
A list of DNS search domains for host-name lookup.
This will be appended to the base search paths generated from DNSPolicy.
Duplicated search paths will be removed.
items:
type: string
type: array
type: object
policy:
description: The DNS Policy for the application pod.
type: string
type: object
env:
description: An array of environment variables for the application
container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ spec:
path: autoscaling.maxReplicas
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: The DNS Policy for the application pod.
displayName: DNS Policy
path: dns.policy
- description: Probe to determine successful initialization. If specified, other
probes are not executed until this completes successfully.
displayName: Startup Probe
Expand All @@ -85,12 +88,6 @@ spec:
- description: The list of TopologySpreadConstraints for the application pod.
displayName: Constraints
path: topologySpreadConstraints.constraints
- description: Whether the operator should disable its default set of TopologySpreadConstraints.
Defaults to false.
displayName: Disable Operator Defaults
path: topologySpreadConstraints.disableOperatorDefaults
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: Name of the application. Defaults to the name of this custom
resource.
displayName: Application Name
Expand All @@ -102,6 +99,9 @@ spec:
path: autoscaling.minReplicas
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:number
- description: The DNS Config for the application pod.
displayName: DNS Config
path: dns.config
- description: Periodic probe of container service readiness. Container will
be removed from service endpoints if the probe fails.
displayName: Readiness Probe
Expand All @@ -112,6 +112,12 @@ spec:
path: serviceAccount.name
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:text
- description: Whether the operator should disable its default set of TopologySpreadConstraints.
Defaults to false.
displayName: Disable Operator Defaults
path: topologySpreadConstraints.disableOperatorDefaults
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: Version of the application.
displayName: Application Version
path: applicationVersion
Expand Down Expand Up @@ -320,6 +326,9 @@ spec:
the scheduler to schedule pods on nodes with matching taints.
displayName: Tolerations
path: tolerations
- description: DNS settings for the pod.
displayName: DNS
path: dns
- description: Labels to set on ServiceMonitor.
displayName: Monitoring Labels
path: monitoring.labels
Expand Down
44 changes: 44 additions & 0 deletions internal/deploy/kubectl/runtime-component-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,50 @@ spec:
description: Disable information about services being injected into
the application pod's environment variables. Default to false.
type: boolean
dns:
description: DNS settings for the pod.
properties:
config:
description: The DNS Config for the application pod.
properties:
nameservers:
description: |-
A list of DNS name server IP addresses.
This will be appended to the base nameservers generated from DNSPolicy.
Duplicated nameservers will be removed.
items:
type: string
type: array
options:
description: |-
A list of DNS resolver options.
This will be merged with the base options generated from DNSPolicy.
Duplicated entries will be removed. Resolution options given in Options
will override those that appear in the base DNSPolicy.
items:
description: PodDNSConfigOption defines DNS resolver options
of a pod.
properties:
name:
description: Required.
type: string
value:
type: string
type: object
type: array
searches:
description: |-
A list of DNS search domains for host-name lookup.
This will be appended to the base search paths generated from DNSPolicy.
Duplicated search paths will be removed.
items:
type: string
type: array
type: object
policy:
description: The DNS Policy for the application pod.
type: string
type: object
env:
description: An array of environment variables for the application
container.
Expand Down
Loading

0 comments on commit 36ee3ed

Please sign in to comment.