Skip to content

Commit

Permalink
Finish missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dtantsur committed Nov 17, 2023
1 parent cd139a5 commit 0c99407
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 49 deletions.
11 changes: 10 additions & 1 deletion api/v1alpha1/ironic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ import (
// Inspection defines inspection settings
type Inspection struct {
// Collectors is a list of inspection collectors to enable.
// See https://docs.openstack.org/ironic-python-agent/latest/admin/how_it_works.html#inspection-data for details.
// +optional
Collectors []string `json:"collectors,omitempty"`

// List of interfaces to inspect for VLANs.
// This can be interface names (to collect all VLANs using LLDP) or pairs <interface>.<vlan ID>.
// +optional
VLANInterfaces []string `json:"vlanInterfaces,omitempty"`
}

Expand Down Expand Up @@ -88,7 +92,7 @@ type Networking struct {
DHCP *DHCP `json:"dhcp,omitempty"`

// ExternalIP is used for accessing API and the image server from remote hosts.
// This settings only applies to virtual media deployments.
// This settings only applies to virtual media deployments. The IP will not be accessed from the cluster itself.
// +optional
ExternalIP string `json:"externalIP,omitempty"`

Expand Down Expand Up @@ -179,6 +183,11 @@ type IronicSpec struct {
// +optional
TLSRef corev1.LocalObjectReference `json:"tlsRef,omitempty"`

// RamdiskExtraKernelParams is a string with kernel parameters to pass to the provisioning/inspection ramdisk.
// Will not take effect if the host uses a pre-built ISO (either through its PreprovisioningImage or via the DEPLOY_ISO_URL baremetal-operator parameter).
// +optional
RamdiskExtraKernelParams string `json:"ramdiskExtraKernelParams,omitempty"`

// RamdiskSSHKey is the contents of the public key to inject into the ramdisk for debugging purposes.
// +optional
RamdiskSSHKey string `json:"ramdiskSSHKey,omitempty"`
Expand Down
16 changes: 13 additions & 3 deletions config/crd/bases/metal3.io_ironics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ spec:
properties:
collectors:
description: Collectors is a list of inspection collectors to
enable.
enable. See https://docs.openstack.org/ironic-python-agent/latest/admin/how_it_works.html#inspection-data
for details.
items:
type: string
type: array
vlanInterfaces:
description: List of interfaces to inspect for VLANs.
description: List of interfaces to inspect for VLANs. This can
be interface names (to collect all VLANs using LLDP) or pairs
<interface>.<vlan ID>.
items:
type: string
type: array
Expand Down Expand Up @@ -171,7 +174,8 @@ spec:
externalIP:
description: ExternalIP is used for accessing API and the image
server from remote hosts. This settings only applies to virtual
media deployments.
media deployments. The IP will not be accessed from the cluster
itself.
type: string
imageServerPort:
default: 6180
Expand Down Expand Up @@ -204,6 +208,12 @@ spec:
type: string
type: array
type: object
ramdiskExtraKernelParams:
description: RamdiskExtraKernelParams is a string with kernel parameters
to pass to the provisioning/inspection ramdisk. Will not take effect
if the host uses a pre-built ISO (either through its PreprovisioningImage
or via the DEPLOY_ISO_URL baremetal-operator parameter).
type: string
ramdiskSSHKey:
description: RamdiskSSHKey is the contents of the public key to inject
into the ramdisk for debugging purposes.
Expand Down
70 changes: 25 additions & 45 deletions pkg/ironic/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ func buildCommonEnvVars(ironic *metal3api.Ironic) []corev1.EnvVar {
}
}

if ironic.Spec.RamdiskSSHKey != "" {
result = append(result,
corev1.EnvVar{
Name: "IRONIC_RAMDISK_SSH_KEY",
Value: strings.Trim(ironic.Spec.RamdiskSSHKey, " \t\n\r"),
},
)
}
result = appendStringEnv(result,
"IRONIC_KERNEL_PARAMS", strings.Trim(ironic.Spec.RamdiskExtraKernelParams, " \t\n\r"))

result = appendStringEnv(result,
"IRONIC_RAMDISK_SSH_KEY", strings.Trim(ironic.Spec.RamdiskSSHKey, " \t\n\r"))

result = appendListOfStringsEnv(result,
"IRONIC_IPA_COLLECTORS", ironic.Spec.Inspection.Collectors, ",")

result = appendListOfStringsEnv(result,
"IRONIC_INSPECTOR_VLAN_INTERFACES", ironic.Spec.Inspection.VLANInterfaces, ",")

return result
}
Expand Down Expand Up @@ -174,6 +177,8 @@ func buildIronicEnvVars(ironic *metal3api.Ironic, db *metal3api.IronicDatabase,
)
}

result = appendStringEnv(result, "IRONIC_EXTERNAL_IP", ironic.Spec.Networking.ExternalIP)

return result
}

Expand Down Expand Up @@ -350,31 +355,14 @@ func newDnsmasqContainer(ironic *metal3api.Ironic) corev1.Container {
Value: buildDHCPRange(dhcp),
})

dns := buildDNSIP(dhcp)
if dns != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "DNS_IP",
Value: dns,
})
}
if dhcp.GatewayAddress != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "GATEWAY_IP",
Value: dhcp.GatewayAddress,
})
}
if len(dhcp.Hosts) > 0 {
envVars = append(envVars, corev1.EnvVar{
Name: "DHCP_HOSTS",
Value: strings.Join(dhcp.Hosts, ";"),
})
}
if len(dhcp.Ignore) > 0 {
envVars = append(envVars, corev1.EnvVar{
Name: "DHCP_IGNORE",
Value: strings.Join(dhcp.Ignore, ","),
})
}
envVars = appendStringEnv(envVars,
"DNS_IP", buildDNSIP(dhcp))
envVars = appendStringEnv(envVars,
"GATEWAY_IP", dhcp.GatewayAddress)
envVars = appendListOfStringsEnv(envVars,
"DHCP_HOSTS", dhcp.Hosts, ";")
envVars = appendListOfStringsEnv(envVars,
"DHCP_IGNORE", dhcp.Ignore, ",")

probe := newProbe(corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Expand Down Expand Up @@ -413,18 +401,10 @@ func newIronicPodTemplate(ironic *metal3api.Ironic, db *metal3api.IronicDatabase
}

var ipaDownloaderVars []corev1.EnvVar
if ironic.Spec.Images.AgentDownloadURL != "" {
ipaDownloaderVars = append(ipaDownloaderVars, corev1.EnvVar{
Name: "IPA_BASEURI",
Value: ironic.Spec.Images.AgentDownloadURL,
})
}
if ironic.Spec.Images.AgentBranch != "" {
ipaDownloaderVars = append(ipaDownloaderVars, corev1.EnvVar{
Name: "IPA_BRANCH",
Value: ironic.Spec.Images.AgentBranch,
})
}
ipaDownloaderVars = appendStringEnv(ipaDownloaderVars,
"IPA_BASEURI", ironic.Spec.Images.AgentDownloadURL)
ipaDownloaderVars = appendStringEnv(ipaDownloaderVars,
"IPA_BRANCH", ironic.Spec.Images.AgentBranch)

volumes, mounts := buildIronicVolumesAndMounts(ironic, db)
sharedVolumeMount := mounts[0]
Expand Down
22 changes: 22 additions & 0 deletions pkg/ironic/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,25 @@ func newProbe(handler corev1.ProbeHandler) *corev1.Probe {
func isReady(conditions []metav1.Condition) bool {
return meta.IsStatusConditionTrue(conditions, string(metal3api.IronicStatusAvailable))
}

func appendStringEnv(envVars []corev1.EnvVar, name string, value string) []corev1.EnvVar {
if value != "" {
return append(envVars, corev1.EnvVar{
Name: name,
Value: value,
})
}

return envVars
}

func appendListOfStringsEnv(envVars []corev1.EnvVar, name string, value []string, sep string) []corev1.EnvVar {
if len(value) > 0 {
return append(envVars, corev1.EnvVar{
Name: name,
Value: strings.Join(value, sep),
})
}

return envVars
}

0 comments on commit 0c99407

Please sign in to comment.