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

Grow volumes on hardened overcloud-full image #844

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions api/v1beta1/openstackbaremetalset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/v1beta2/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta2/openstackvmset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions controllers/openstackbaremetalset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
1 change: 1 addition & 0 deletions controllers/openstackcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions controllers/openstackvmset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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{
Expand Down
34 changes: 34 additions & 0 deletions pkg/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a regexp to match all the different default Controller* roles?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is copied from the playbook used in a traditional director deployment so I've kept is consistent

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%",
}
}
24 changes: 4 additions & 20 deletions pkg/common/template_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions templates/baremetalset/cloudinit/userdata
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions templates/vmset/cloudinit/userdata
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}