From 1ccb32f60589553d7c4313ddae3bfcf50dcdbee2 Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Thu, 4 Dec 2025 13:02:54 -0500 Subject: [PATCH 1/2] Add the .spec.hostAliases CR field --- api/v1/runtimecomponent_types.go | 8 +++++++ api/v1/zz_generated.deepcopy.go | 7 +++++++ .../rc.app.stacks_runtimecomponents.yaml | 21 +++++++++++++++++++ ...ntime-component.clusterserviceversion.yaml | 6 +++++- common/types.go | 1 + .../rc.app.stacks_runtimecomponents.yaml | 21 +++++++++++++++++++ ...ntime-component.clusterserviceversion.yaml | 4 ++++ .../deploy/kubectl/runtime-component-crd.yaml | 21 +++++++++++++++++++ .../daily/base/runtime-component-crd.yaml | 21 +++++++++++++++++++ utils/utils.go | 4 ++++ 10 files changed, 113 insertions(+), 1 deletion(-) diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index 9c875478..3163027d 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..cc5fae83 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -681,6 +681,13 @@ func (in *RuntimeComponentSpec) DeepCopyInto(out *RuntimeComponentSpec) { *out = new(RuntimeComponentDNS) (*in).DeepCopyInto(*out) } + if in.HostAliases != nil { + in, out := &in.HostAliases, &out.HostAliases + *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 18e5bc0f..7e3284bf 100644 --- a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml +++ b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml @@ -1950,6 +1950,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 faf9d828..84753673 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2025-10-30T19:51:52Z" + createdAt: "2025-12-04T18:01:36Z" description: Deploys any runtime component with dynamic and auto-tuning configuration features.operators.openshift.io/disconnected: "true" features.operators.openshift.io/fips-compliant: "true" @@ -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..e36ff0c0 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 89b5e68b..d6dac0c4 100644 --- a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml +++ b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml @@ -1946,6 +1946,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 c0a70316..b1a955be 100644 --- a/internal/deploy/kubectl/runtime-component-crd.yaml +++ b/internal/deploy/kubectl/runtime-component-crd.yaml @@ -1949,6 +1949,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 c0a70316..b1a955be 100644 --- a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml +++ b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml @@ -1949,6 +1949,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..9c44a970 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 len(ba.GetHostAliases()) > 0 { + pts.Spec.HostAliases = ba.GetHostAliases() + } + pts.Spec.InitContainers = ba.GetInitContainers() appContainer.VolumeMounts = ba.GetVolumeMounts() From 7d2acc4b2262b8d542e6b449b60cb2d76029f0db Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Fri, 5 Dec 2025 14:17:42 -0500 Subject: [PATCH 2/2] Set pointer to host aliases --- api/v1/runtimecomponent_types.go | 4 ++-- api/v1/zz_generated.deepcopy.go | 10 +++++++--- common/types.go | 2 +- utils/utils.go | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index 3163027d..fe3ce0de 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -166,7 +166,7 @@ type RuntimeComponentSpec struct { // 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"` + HostAliases *[]corev1.HostAlias `json:"hostAliases,omitempty"` } // Defines the DNS @@ -1076,7 +1076,7 @@ func (cr *RuntimeComponentTopologySpreadConstraints) GetDisableOperatorDefaults( return cr.DisableOperatorDefaults } -func (cr *RuntimeComponent) GetHostAliases() []corev1.HostAlias { +func (cr *RuntimeComponent) GetHostAliases() *[]corev1.HostAlias { return cr.Spec.HostAliases } diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index cc5fae83..f46e2870 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -683,9 +683,13 @@ func (in *RuntimeComponentSpec) DeepCopyInto(out *RuntimeComponentSpec) { } if in.HostAliases != nil { in, out := &in.HostAliases, &out.HostAliases - *out = make([]corev1.HostAlias, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) + *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]) + } } } } diff --git a/common/types.go b/common/types.go index e36ff0c0..9330126c 100644 --- a/common/types.go +++ b/common/types.go @@ -260,5 +260,5 @@ type BaseComponent interface { GetDisableServiceLinks() *bool GetTolerations() []corev1.Toleration GetDNS() BaseComponentDNS - GetHostAliases() []corev1.HostAlias + GetHostAliases() *[]corev1.HostAlias } diff --git a/utils/utils.go b/utils/utils.go index 9c44a970..0788776b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -702,8 +702,8 @@ func CustomizePodSpec(pts *corev1.PodTemplateSpec, ba common.BaseComponent) { appContainer.Env = ba.GetEnv() appContainer.EnvFrom = ba.GetEnvFrom() - if len(ba.GetHostAliases()) > 0 { - pts.Spec.HostAliases = ba.GetHostAliases() + if ba.GetHostAliases() != nil { + pts.Spec.HostAliases = *ba.GetHostAliases() } pts.Spec.InitContainers = ba.GetInitContainers()