diff --git a/api/v1beta1/openstackbaremetalset_types.go b/api/v1beta1/openstackbaremetalset_types.go index 36f64e4c..2d28be27 100644 --- a/api/v1beta1/openstackbaremetalset_types.go +++ b/api/v1beta1/openstackbaremetalset_types.go @@ -54,6 +54,9 @@ type OpenStackBaremetalSetSpec struct { // Note that subsequent TripleO deployment will overwrite these values BootstrapDNS []string `json:"bootstrapDns,omitempty"` DNSSearchDomains []string `json:"dnsSearchDomains,omitempty"` + // GrowvolsArgs - arguments to the growvols command to expand logical volumes after provisioning + // Note requires the command to exist on the base image + GrowvolsArgs []string `json:"growvolsArgs,omitempty"` } // OpenStackBaremetalSetStatus defines the observed state of OpenStackBaremetalSet diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 760135b9..3daf6544 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -707,6 +707,11 @@ func (in *OpenStackBaremetalSetSpec) DeepCopyInto(out *OpenStackBaremetalSetSpec *out = make([]string, len(*in)) copy(*out, *in) } + if in.GrowvolsArgs != nil { + in, out := &in.GrowvolsArgs, &out.GrowvolsArgs + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackBaremetalSetSpec. diff --git a/api/v1beta2/openstackcontrolplane_types.go b/api/v1beta2/openstackcontrolplane_types.go index 89e25665..d25debe4 100644 --- a/api/v1beta2/openstackcontrolplane_types.go +++ b/api/v1beta2/openstackcontrolplane_types.go @@ -126,6 +126,10 @@ type OpenStackVirtualMachineRoleSpec struct { // +kubebuilder:validation:Optional // NodeSelector to target subset of worker nodes running this VMset NodeSelector map[string]string `json:"nodeSelector,omitempty"` + + // GrowvolsArgs - arguments to the growvols command to expand logical volumes after provisioning + // Note requires the command to exist on the base image + GrowvolsArgs []string `json:"growvolsArgs,omitempty"` } // OpenStackControlPlaneStatus defines the observed state of OpenStackControlPlane diff --git a/api/v1beta2/openstackvmset_types.go b/api/v1beta2/openstackvmset_types.go index 74b72089..428c1dcb 100644 --- a/api/v1beta2/openstackvmset_types.go +++ b/api/v1beta2/openstackvmset_types.go @@ -76,6 +76,10 @@ type OpenStackVMSetSpec struct { // +kubebuilder:validation:Optional // NodeSelector to target subset of worker nodes running this VMset NodeSelector map[string]string `json:"nodeSelector,omitempty"` + + // GrowvolsArgs - arguments to the growvols command to expand logical volumes after provisioning + // Note requires the command to exist on the base image + GrowvolsArgs []string `json:"growvolsArgs,omitempty"` } // OpenStackVMSetDisk defines additional disk properties diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 14165b5c..cd128c83 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -483,6 +483,11 @@ func (in *OpenStackVMSetSpec) DeepCopyInto(out *OpenStackVMSetSpec) { (*out)[key] = val } } + if in.GrowvolsArgs != nil { + in, out := &in.GrowvolsArgs, &out.GrowvolsArgs + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackVMSetSpec. @@ -551,6 +556,11 @@ func (in *OpenStackVirtualMachineRoleSpec) DeepCopyInto(out *OpenStackVirtualMac (*out)[key] = val } } + if in.GrowvolsArgs != nil { + in, out := &in.GrowvolsArgs, &out.GrowvolsArgs + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackVirtualMachineRoleSpec. diff --git a/controllers/openstackbaremetalset_controller.go b/controllers/openstackbaremetalset_controller.go index e5d9548e..840a1891 100644 --- a/controllers/openstackbaremetalset_controller.go +++ b/controllers/openstackbaremetalset_controller.go @@ -908,6 +908,14 @@ func (r *OpenStackBaremetalSetReconciler) baremetalHostProvision( templateParameters["Hostname"] = bmhStatus.Hostname templateParameters["DomainName"] = osNetCfg.Spec.DomainName + if instance.Spec.GrowvolsArgs != nil && len(instance.Spec.GrowvolsArgs) > 0 { + templateParameters["GrowvolsArgs"] = instance.Spec.GrowvolsArgs + + } else { + // use default for the role name + templateParameters["GrowvolsArgs"] = common.GetRoleGrowvolsArgs(instance.Spec.RoleName) + } + // // use same NodeRootPassword paremater as tripleo have // diff --git a/controllers/openstackcontrolplane_controller.go b/controllers/openstackcontrolplane_controller.go index c2500fc3..5f53d596 100644 --- a/controllers/openstackcontrolplane_controller.go +++ b/controllers/openstackcontrolplane_controller.go @@ -773,6 +773,7 @@ func (r *OpenStackControlPlaneReconciler) createOrUpdateVMSets( vmSet.Spec.PasswordSecret = instance.Spec.PasswordSecret } vmSet.Spec.NodeSelector = vmRole.NodeSelector + vmSet.Spec.GrowvolsArgs = vmRole.GrowvolsArgs err := controllerutil.SetControllerReference(instance, vmSet, r.Scheme) if err != nil { diff --git a/controllers/openstackvmset_controller.go b/controllers/openstackvmset_controller.go index 4eeac144..c93543f6 100644 --- a/controllers/openstackvmset_controller.go +++ b/controllers/openstackvmset_controller.go @@ -350,6 +350,14 @@ func (r *OpenStackVMSetReconciler) Reconcile(ctx context.Context, req ctrl.Reque // templateParameters["DomainName"] = osNetCfg.Spec.DomainName + if instance.Spec.GrowvolsArgs != nil && len(instance.Spec.GrowvolsArgs) > 0 { + templateParameters["GrowvolsArgs"] = instance.Spec.GrowvolsArgs + + } else { + // use default for the role name + templateParameters["GrowvolsArgs"] = common.GetRoleGrowvolsArgs(instance.Spec.RoleName) + } + // // check if PasswordSecret got specified and if it exists before creating the controlplane // @@ -849,6 +857,12 @@ func (r *OpenStackVMSetReconciler) vmCreateInstance( Machine: &virtv1.Machine{ Type: "", }, + Features: &virtv1.Features{ + SMM: &virtv1.FeatureState{Enabled: &trueValue}, + }, + Firmware: &virtv1.Firmware{ + Bootloader: &virtv1.Bootloader{EFI: &virtv1.EFI{}}, + }, }, Volumes: []virtv1.Volume{}, Networks: []virtv1.Network{ diff --git a/pkg/common/const.go b/pkg/common/const.go index cd0d9d3f..c00127fb 100644 --- a/pkg/common/const.go +++ b/pkg/common/const.go @@ -51,3 +51,37 @@ const ( // TripleORolesDataFile - TripleORolesDataFile = "roles_data.yaml" ) + +// GetRoleGrowvolsArgs - return default growvols args for the given tripleo role name +func GetRoleGrowvolsArgs(role string) []string { + if role == "Controller" { + return []string{ + "/=8GB", + "/tmp=1GB", + "/var/log=10GB", + "/var/log/audit=2GB", + "/home=1GB", + "/var=90%", + "/srv=10%", + } + } + if role == "ObjectStorage" { + return []string{ + "/=8GB", + "/tmp=1GB", + "/var/log=10GB", + "/var/log/audit=2GB", + "/home=1GB", + "/var=10%", + "/srv=90%", + } + } + return []string{ + "/=8GB", + "/tmp=1GB", + "/var/log=10GB", + "/var/log/audit=2GB", + "/home=1GB", + "/var=100%", + } +} diff --git a/pkg/common/template_util.go b/pkg/common/template_util.go index 88bfcf30..8f1e2bb9 100644 --- a/pkg/common/template_util.go +++ b/pkg/common/template_util.go @@ -12,6 +12,8 @@ import ( "github.com/openstack-k8s-operators/osp-director-operator/api/shared" corev1 "k8s.io/api/core/v1" + + "github.com/Masterminds/sprig" ) // TType - TemplateType @@ -108,26 +110,12 @@ func ExecuteTemplate(templateFile string, data interface{}) (string, error) { return renderedTemplate, nil } -// template function to increment an int -func add(x, y int) int { - return x + y -} - -// template function to lower a string -func lower(s string) string { - return strings.ToLower(s) -} - // ExecuteTemplateData creates a template from string and // execute it with the specified data func ExecuteTemplateData(templateData string, data interface{}) (string, error) { var buff bytes.Buffer - funcs := template.FuncMap{ - "add": add, - "lower": lower, - } - tmpl, err := template.New("tmp").Funcs(funcs).Parse(templateData) + tmpl, err := template.New("tmp").Funcs(sprig.TxtFuncMap()).Parse(templateData) if err != nil { return "", err } @@ -162,11 +150,7 @@ func ExecuteTemplateFile(filename string, data interface{}) (string, error) { } file := string(b) var buff bytes.Buffer - funcs := template.FuncMap{ - "add": add, - "lower": lower, - } - tmpl, err := template.New("tmp").Funcs(funcs).Parse(file) + tmpl, err := template.New("tmp").Funcs(sprig.TxtFuncMap()).Parse(file) if err != nil { return "", err } diff --git a/templates/baremetalset/cloudinit/userdata b/templates/baremetalset/cloudinit/userdata index bda5b2a5..bc89b90d 100644 --- a/templates/baremetalset/cloudinit/userdata +++ b/templates/baremetalset/cloudinit/userdata @@ -15,3 +15,6 @@ chpasswd: bootcmd: # fix BLS entries - set -x; if [ -e /boot/loader/entries/ffffffffffffffffffffffffffffffff-* ]; then MACHINEID=$(cat /etc/machine-id) && rename "ffffffffffffffffffffffffffffffff" "$MACHINEID" /boot/loader/entries/ffffffffffffffffffffffffffffffff-* ; fi +runcmd: + # grow volumes on hardened image if command exists + - set -x; if [ -e /usr/local/sbin/growvols ]; then /usr/local/sbin/growvols --yes {{ range .GrowvolsArgs}}'{{.|trim}}' {{end}}; fi diff --git a/templates/vmset/cloudinit/userdata b/templates/vmset/cloudinit/userdata index 07f60f62..1c4a8809 100644 --- a/templates/vmset/cloudinit/userdata +++ b/templates/vmset/cloudinit/userdata @@ -31,4 +31,6 @@ runcmd: - set -x; for if in $(/bin/nmcli -f device,state device status | egrep '[[:space:]]+connected' | awk '{print $1}'); do nmcli device modify $if ipv6.method link-local; done # Disable IPv6 autoconf per default, we only want the ooo static IP config - set -x; echo 'IPV6_AUTOCONF=no' >> /etc/sysconfig/network + # grow volumes on hardened image if command exists + - set -x; if [ -e /usr/local/sbin/growvols ]; then /usr/local/sbin/growvols --yes {{ range .GrowvolsArgs}}'{{.|trim}}' {{end}}; fi {{- end }}