diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index 9c875478..fe3ce0de 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -163,6 +163,10 @@ type RuntimeComponentSpec struct { // DNS settings for the pod. // +operator-sdk:csv:customresourcedefinitions:order=29,type=spec,displayName="DNS" DNS *RuntimeComponentDNS `json:"dns,omitempty"` + + // The list of hosts and IPs that will be inejcted into the application pod's hosts file + // +operator-sdk:csv:customresourcedefinitions:order=30,type=spec,displayName="Host Aliases" + HostAliases *[]corev1.HostAlias `json:"hostAliases,omitempty"` } // Defines the DNS @@ -1072,6 +1076,10 @@ func (cr *RuntimeComponentTopologySpreadConstraints) GetDisableOperatorDefaults( return cr.DisableOperatorDefaults } +func (cr *RuntimeComponent) GetHostAliases() *[]corev1.HostAlias { + return cr.Spec.HostAliases +} + // Initialize the RuntimeComponent instance func (cr *RuntimeComponent) Initialize() { if cr.Spec.PullPolicy == nil { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index b29eed28..f46e2870 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -681,6 +681,17 @@ func (in *RuntimeComponentSpec) DeepCopyInto(out *RuntimeComponentSpec) { *out = new(RuntimeComponentDNS) (*in).DeepCopyInto(*out) } + if in.HostAliases != nil { + in, out := &in.HostAliases, &out.HostAliases + *out = new([]corev1.HostAlias) + if **in != nil { + in, out := *in, *out + *out = make([]corev1.HostAlias, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuntimeComponentSpec. diff --git a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml index 35d6d5fe..adcef2a9 100644 --- a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml +++ b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml @@ -1983,6 +1983,27 @@ spec: description: Expose the application externally via a Route, a Knative Route or an Ingress resource. type: boolean + hostAliases: + description: The list of hosts and IPs that will be inejcted into + the application pod's hosts file + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array initContainers: description: List of containers to run before other containers in a pod. diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index e75f09e8..703b9670 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -419,6 +419,10 @@ spec: - description: DNS settings for the pod. displayName: DNS path: dns + - description: The list of hosts and IPs that will be inejcted into the application + pod's hosts file + displayName: Host Aliases + path: hostAliases - description: Labels to set on ServiceMonitor. displayName: Monitoring Labels path: monitoring.labels diff --git a/common/types.go b/common/types.go index c9232ad6..9330126c 100644 --- a/common/types.go +++ b/common/types.go @@ -260,4 +260,5 @@ type BaseComponent interface { GetDisableServiceLinks() *bool GetTolerations() []corev1.Toleration GetDNS() BaseComponentDNS + GetHostAliases() *[]corev1.HostAlias } diff --git a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml index 2a0b5f72..0f2452c2 100644 --- a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml +++ b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml @@ -1979,6 +1979,27 @@ spec: description: Expose the application externally via a Route, a Knative Route or an Ingress resource. type: boolean + hostAliases: + description: The list of hosts and IPs that will be inejcted into + the application pod's hosts file + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array initContainers: description: List of containers to run before other containers in a pod. diff --git a/config/manifests/bases/runtime-component.clusterserviceversion.yaml b/config/manifests/bases/runtime-component.clusterserviceversion.yaml index d147ca9a..a3e6b9c8 100644 --- a/config/manifests/bases/runtime-component.clusterserviceversion.yaml +++ b/config/manifests/bases/runtime-component.clusterserviceversion.yaml @@ -353,6 +353,10 @@ spec: - description: DNS settings for the pod. displayName: DNS path: dns + - description: The list of hosts and IPs that will be inejcted into the application + pod's hosts file + displayName: Host Aliases + path: hostAliases - description: Labels to set on ServiceMonitor. displayName: Monitoring Labels path: monitoring.labels diff --git a/internal/deploy/kubectl/runtime-component-crd.yaml b/internal/deploy/kubectl/runtime-component-crd.yaml index 5eadacb5..794215ce 100644 --- a/internal/deploy/kubectl/runtime-component-crd.yaml +++ b/internal/deploy/kubectl/runtime-component-crd.yaml @@ -1982,6 +1982,27 @@ spec: description: Expose the application externally via a Route, a Knative Route or an Ingress resource. type: boolean + hostAliases: + description: The list of hosts and IPs that will be inejcted into + the application pod's hosts file + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array initContainers: description: List of containers to run before other containers in a pod. diff --git a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml index 5eadacb5..794215ce 100644 --- a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml +++ b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml @@ -1982,6 +1982,27 @@ spec: description: Expose the application externally via a Route, a Knative Route or an Ingress resource. type: boolean + hostAliases: + description: The list of hosts and IPs that will be inejcted into + the application pod's hosts file + items: + description: |- + HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the + pod's hosts file. + properties: + hostnames: + description: Hostnames for the above IP address. + items: + type: string + type: array + x-kubernetes-list-type: atomic + ip: + description: IP address of the host file entry. + type: string + required: + - ip + type: object + type: array initContainers: description: List of containers to run before other containers in a pod. diff --git a/utils/utils.go b/utils/utils.go index 3d016372..0788776b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -702,6 +702,10 @@ func CustomizePodSpec(pts *corev1.PodTemplateSpec, ba common.BaseComponent) { appContainer.Env = ba.GetEnv() appContainer.EnvFrom = ba.GetEnvFrom() + if ba.GetHostAliases() != nil { + pts.Spec.HostAliases = *ba.GetHostAliases() + } + pts.Spec.InitContainers = ba.GetInitContainers() appContainer.VolumeMounts = ba.GetVolumeMounts()