Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine whether initcontainer is needed through IPAConfig options #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions api/v1alpha1/ironic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ type Images struct {
// +kubebuilder:default=quay.io/metal3-io/ironic-ipa-downloader
// +optional
RamdiskDownloader string `json:"ramdiskDownloader,omitempty"`

// DisableRamdiskDownloader turns off the ramdisk downloader.
// +kubebuilder:default=false
// +optional
DisableRamdiskDownloader bool `json:"disableRamdiskDownloader,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This should not be part of Images, especially since the Images structure in its current form will be gone.

}

// IronicSpec defines the desired state of Ironic
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/ironic_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func validateIronic(ironic *IronicSpec, old *IronicSpec) error {
}
}

if ironic.Images.AgentDownloadURL != "" {
if !ironic.Images.DisableRamdiskDownloader && ironic.Images.AgentDownloadURL != "" {
if _, err := url.Parse(ironic.Images.AgentDownloadURL); err != nil {
return fmt.Errorf("images.agentDownloadURL is not a valid URL: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/metal3.io_ironics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ spec:
AgentDownloadURL is the base URL from which IPA should be downloaded.
The default value should be good for most users.
type: string
disableRamdiskDownloader:
default: false
description: DisableRamdiskDownloader turns off the ramdisk downloader.
type: boolean
ironic:
default: quay.io/metal3-io/ironic
description: Ironic is the Ironic image (including httpd).
Expand Down
47 changes: 26 additions & 21 deletions pkg/ironic/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,32 +417,15 @@ func newIronicPodTemplate(ironic *metal3api.Ironic, db *metal3api.IronicDatabase
htpasswd = apiSecret.Name
}

var ipaDownloaderVars []corev1.EnvVar
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]
initContainers := []corev1.Container{
{
Name: "ipa-downloader",
Image: ironic.Spec.Images.RamdiskDownloader,
Env: ipaDownloaderVars,
VolumeMounts: []corev1.VolumeMount{sharedVolumeMount},
SecurityContext: &corev1.SecurityContext{
RunAsUser: ptr.To(ironicUser),
RunAsGroup: ptr.To(ironicGroup),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
},
},

var initContainers []corev1.Container
if !ironic.Spec.Images.DisableRamdiskDownloader {
initContainers = newInitContainers(ironic, sharedVolumeMount)
}

ironicPorts, httpdPorts := buildIronicHttpdPorts(ironic)

ironicHandler := newURLProbeHandler(ironic, ironic.Spec.TLSRef.Name != "", int(ironic.Spec.Networking.APIPort), "/v1")
httpdHandler := newURLProbeHandler(ironic, false, int(ironic.Spec.Networking.ImageServerPort), "/images")

Expand Down Expand Up @@ -519,3 +502,25 @@ func newIronicPodTemplate(ironic *metal3api.Ironic, db *metal3api.IronicDatabase
},
}, nil
}

func newInitContainers(ironic *metal3api.Ironic, sharedVolumeMount corev1.VolumeMount) []corev1.Container {
var ipaDownloaderVars []corev1.EnvVar
ipaDownloaderVars = appendStringEnv(ipaDownloaderVars, "IPA_BASEURI", ironic.Spec.Images.AgentDownloadURL)
ipaDownloaderVars = appendStringEnv(ipaDownloaderVars, "IPA_BRANCH", ironic.Spec.Images.AgentBranch)

return []corev1.Container{
{
Name: "ipa-downloader",
Image: ironic.Spec.Images.RamdiskDownloader,
Env: ipaDownloaderVars,
VolumeMounts: []corev1.VolumeMount{sharedVolumeMount},
SecurityContext: &corev1.SecurityContext{
RunAsUser: ptr.To(ironicUser),
RunAsGroup: ptr.To(ironicGroup),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
},
},
}
}
Loading