Skip to content

Commit

Permalink
Improve field alignment of structs
Browse files Browse the repository at this point in the history
This change improves the field alignment in our structs to
reduce the overall memory footprint required for each struct.
We do this by aligning like types within the structs to reduce
the amount of padding required to align each object in memory.

Signed-off-by: Brendan Shephard <[email protected]>
  • Loading branch information
bshephar committed Apr 23, 2024
1 parent 91a64b3 commit b124ce7
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 262 deletions.
81 changes: 40 additions & 41 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ type AnsibleOpts struct {
// +kubebuilder:validation:Optional
AnsibleHost string `json:"ansibleHost,omitempty"`

// AnsiblePort SSH port for Ansible connection
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number"}
AnsiblePort int `json:"ansiblePort,omitempty"`

// AnsibleVars for configuring ansible
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Expand All @@ -61,30 +56,58 @@ type AnsibleOpts struct {
// Values defined by an AnsibleVars with a duplicate key take precedence.
// +kubebuilder:validation:Optional
AnsibleVarsFrom []AnsibleVarsFromSource `json:"ansibleVarsFrom,omitempty"`

// AnsiblePort SSH port for Ansible connection
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number"}
AnsiblePort int `json:"ansiblePort,omitempty"`
}

// NodeSection defines the top level attributes inherited by nodes in the CR.
type NodeSection struct {
// HostName - node name
// ExtraMounts containing files which can be mounted into an Ansible Execution Pod
// +kubebuilder:validation:Optional
HostName string `json:"hostName,omitempty"`
ExtraMounts []storage.VolMounts `json:"extraMounts,omitempty"`

// Networks - Instance networks
// +kubebuilder:validation:Optional
Networks []infranetworkv1.IPSetNetwork `json:"networks,omitempty"`

// ManagementNetwork - Name of network to use for management (SSH/Ansible)
// UserData node specific user-data
// +kubebuilder:validation:Optional
ManagementNetwork string `json:"managementNetwork,omitempty"`
UserData *corev1.SecretReference `json:"userData,omitempty"`

// NetworkData node specific network-data
// +kubebuilder:validation:Optional
NetworkData *corev1.SecretReference `json:"networkData,omitempty"`

// Ansible is the group of Ansible related configuration options.
// +kubebuilder:validation:Optional
Ansible AnsibleOpts `json:"ansible,omitempty"`

// HostName - node name
// +kubebuilder:validation:Optional
HostName string `json:"hostName,omitempty"`

// ManagementNetwork - Name of network to use for management (SSH/Ansible)
// +kubebuilder:validation:Optional
ManagementNetwork string `json:"managementNetwork,omitempty"`

// +kubebuilder:validation:Optional
// PreprovisioningNetworkDataName - NetworkData secret name in the local namespace for pre-provisioing
PreprovisioningNetworkDataName string `json:"preprovisioningNetworkDataName,omitempty"`
}

// NodeTemplate is a specification of the node attributes that override top level attributes.
type NodeTemplate struct {
// ExtraMounts containing files which can be mounted into an Ansible Execution Pod
// +kubebuilder:validation:Optional
ExtraMounts []storage.VolMounts `json:"extraMounts,omitempty"`

// Networks - Instance networks
// +kubebuilder:validation:Optional
Networks []infranetworkv1.IPSetNetwork `json:"networks,omitempty"`

// UserData node specific user-data
// +kubebuilder:validation:Optional
UserData *corev1.SecretReference `json:"userData,omitempty"`
Expand All @@ -93,13 +116,6 @@ type NodeSection struct {
// +kubebuilder:validation:Optional
NetworkData *corev1.SecretReference `json:"networkData,omitempty"`

// +kubebuilder:validation:Optional
// PreprovisioningNetworkDataName - NetworkData secret name in the local namespace for pre-provisioing
PreprovisioningNetworkDataName string `json:"preprovisioningNetworkDataName,omitempty"`
}

// NodeTemplate is a specification of the node attributes that override top level attributes.
type NodeTemplate struct {
// AnsibleSSHPrivateKeySecret Name of a private SSH key secret containing
// private SSH key for connecting to node.
// The named secret must be of the form:
Expand All @@ -108,11 +124,6 @@ type NodeTemplate struct {
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:io.kubernetes:Secret"}
AnsibleSSHPrivateKeySecret string `json:"ansibleSSHPrivateKeySecret"`

// Networks - Instance networks
// +kubebuilder:validation:Optional
Networks []infranetworkv1.IPSetNetwork `json:"networks,omitempty"`

// ManagementNetwork - Name of network to use for management (SSH/Ansible)
// +kubebuilder:validation:Optional
// +kubebuilder:default=ctlplane
Expand All @@ -121,22 +132,18 @@ type NodeTemplate struct {
// Ansible is the group of Ansible related configuration options.
// +kubebuilder:validation:Optional
Ansible AnsibleOpts `json:"ansible,omitempty"`

// ExtraMounts containing files which can be mounted into an Ansible Execution Pod
// +kubebuilder:validation:Optional
ExtraMounts []storage.VolMounts `json:"extraMounts,omitempty"`

// UserData node specific user-data
// +kubebuilder:validation:Optional
UserData *corev1.SecretReference `json:"userData,omitempty"`

// NetworkData node specific network-data
// +kubebuilder:validation:Optional
NetworkData *corev1.SecretReference `json:"networkData,omitempty"`
}

// AnsibleEESpec is a specification of the ansible EE attributes
type AnsibleEESpec struct {
// ExtraMounts containing files which can be mounted into an Ansible Execution Pod
ExtraMounts []storage.VolMounts `json:"extraMounts,omitempty"`
// Env is a list containing the environment variables to pass to the pod
Env []corev1.EnvVar `json:"env,omitempty"`
// ExtraVars for ansible execution
ExtraVars map[string]json.RawMessage `json:"extraVars,omitempty"`
// DNSConfig for setting dnsservers
DNSConfig *corev1.PodDNSConfig `json:"dnsConfig,omitempty"`
// NetworkAttachments is a list of NetworkAttachment resource names to pass to the ansibleee resource
// which allows to connect the ansibleee runner to the given network
NetworkAttachments []string `json:"networkAttachments"`
Expand All @@ -148,14 +155,6 @@ type AnsibleEESpec struct {
AnsibleLimit string `json:"ansibleLimit,omitempty"`
// AnsibleSkipTags for ansible execution
AnsibleSkipTags string `json:"ansibleSkipTags,omitempty"`
// ExtraVars for ansible execution
ExtraVars map[string]json.RawMessage `json:"extraVars,omitempty"`
// ExtraMounts containing files which can be mounted into an Ansible Execution Pod
ExtraMounts []storage.VolMounts `json:"extraMounts,omitempty"`
// Env is a list containing the environment variables to pass to the pod
Env []corev1.EnvVar `json:"env,omitempty"`
// DNSConfig for setting dnsservers
DNSConfig *corev1.PodDNSConfig `json:"dnsConfig,omitempty"`
// ServiceAccountName allows to specify what ServiceAccountName do we want
// the ansible execution run with. Without specifying, it will run with
// default serviceaccount
Expand Down
21 changes: 10 additions & 11 deletions api/v1beta1/openstackdataplanedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

// OpenStackDataPlaneDeploymentSpec defines the desired state of OpenStackDataPlaneDeployment
type OpenStackDataPlaneDeploymentSpec struct {

// +kubebuilder:validation:Required
// NodeSets is the list of NodeSets deployed
NodeSets []string `json:"nodeSets"`
Expand Down Expand Up @@ -60,17 +59,9 @@ type OpenStackDataPlaneDeploymentSpec struct {

// OpenStackDataPlaneDeploymentStatus defines the observed state of OpenStackDataPlaneDeployment
type OpenStackDataPlaneDeploymentStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

// NodeSetConditions
NodeSetConditions map[string]condition.Conditions `json:"nodeSetConditions,omitempty" optional:"true"`

// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deployed
Deployed bool `json:"deployed,omitempty" optional:"true"`

// ConfigMapHashes
ConfigMapHashes map[string]string `json:"configMapHashes,omitempty" optional:"true"`

Expand All @@ -80,14 +71,22 @@ type OpenStackDataPlaneDeploymentStatus struct {
// NodeSetHashes
NodeSetHashes map[string]string `json:"nodeSetHashes,omitempty" optional:"true"`

// ContainerImages
ContainerImages map[string]string `json:"containerImages,omitempty"`

// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:io.kubernetes.conditions"}
// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

//ObservedGeneration - the most recent generation observed for this Deployment. If the observed generation is less than the spec generation, then the controller has not processed the latest changes.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// DeployedVersion
DeployedVersion string `json:"deployedVersion,omitempty"`

// ContainerImages
ContainerImages map[string]string `json:"containerImages,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deployed
Deployed bool `json:"deployed,omitempty" optional:"true"`
}

//+kubebuilder:object:root=true
Expand Down
56 changes: 28 additions & 28 deletions api/v1beta1/openstackdataplanenodeset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ type OpenStackDataPlaneNodeSetSpec struct {
// +kubebuilder:validation:Required
Nodes map[string]NodeSection `json:"nodes"`

// SecretMaxSize - Maximum size in bytes of a Kubernetes secret. This size is currently situated around
// 1 MiB (nearly 1 MB).
// +kubebuilder:validation:Optional
// +kubebuilder:default=1048576
SecretMaxSize int `json:"secretMaxSize" yaml:"secretMaxSize"`

// +kubebuilder:validation:Optional
//
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// PreProvisioned - Set to true if the nodes have been Pre Provisioned.
PreProvisioned bool `json:"preProvisioned,omitempty"`

// Env is a list containing the environment variables to pass to the pod
// +kubebuilder:validation:Optional
Env []corev1.EnvVar `json:"env,omitempty"`
Expand All @@ -74,15 +62,27 @@ type OpenStackDataPlaneNodeSetSpec struct {
// Services list
Services []string `json:"services"`

// Tags - Additional tags for NodeSet
// +kubebuilder:validation:Optional
Tags []string `json:"tags,omitempty"`

// SecretMaxSize - Maximum size in bytes of a Kubernetes secret. This size is currently situated around
// 1 MiB (nearly 1 MB).
// +kubebuilder:validation:Optional
// +kubebuilder:default=1048576
SecretMaxSize int `json:"secretMaxSize" yaml:"secretMaxSize"`

// +kubebuilder:validation:Optional
//
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// PreProvisioned - Set to true if the nodes have been Pre Provisioned.
PreProvisioned bool `json:"preProvisioned,omitempty"`

// TLSEnabled - Whether the node set has TLS enabled.
// +kubebuilder:validation:Optional
// +kubebuilder:default=true
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
TLSEnabled bool `json:"tlsEnabled" yaml:"tlsEnabled"`

// Tags - Additional tags for NodeSet
// +kubebuilder:validation:Optional
Tags []string `json:"tags,omitempty"`
}

//+kubebuilder:object:root=true
Expand All @@ -108,19 +108,9 @@ type OpenStackDataPlaneNodeSetStatus struct {
// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deployed
Deployed bool `json:"deployed,omitempty" optional:"true"`

// DeploymentStatuses
DeploymentStatuses map[string]condition.Conditions `json:"deploymentStatuses,omitempty" optional:"true"`

// DNSClusterAddresses
DNSClusterAddresses []string `json:"dnsClusterAddresses,omitempty" optional:"true"`

// CtlplaneSearchDomain
CtlplaneSearchDomain string `json:"ctlplaneSearchDomain,omitempty" optional:"true"`

// AllHostnames
AllHostnames map[string]map[infranetworkv1.NetNameStr]string `json:"allHostnames,omitempty" optional:"true"`

Expand All @@ -133,6 +123,15 @@ type OpenStackDataPlaneNodeSetStatus struct {
// SecretHashes
SecretHashes map[string]string `json:"secretHashes,omitempty" optional:"true"`

// DNSClusterAddresses
DNSClusterAddresses []string `json:"dnsClusterAddresses,omitempty" optional:"true"`

// ContainerImages
ContainerImages map[string]string `json:"containerImages,omitempty" optional:"true"`

// CtlplaneSearchDomain
CtlplaneSearchDomain string `json:"ctlplaneSearchDomain,omitempty" optional:"true"`

// ConfigHash - holds the curret hash of the NodeTemplate and Node sections of the struct.
// This hash is used to determine when new Ansible executions are required to roll
// out config changes.
Expand All @@ -150,8 +149,9 @@ type OpenStackDataPlaneNodeSetStatus struct {
// DeployedVersion
DeployedVersion string `json:"deployedVersion,omitempty"`

// ContainerImages
ContainerImages map[string]string `json:"containerImages,omitempty" optional:"true"`
// +operator-sdk:csv:customresourcedefinitions:type=status,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:booleanSwitch"}
// Deployed
Deployed bool `json:"deployed,omitempty" optional:"true"`
}

//+kubebuilder:object:root=true
Expand Down
20 changes: 10 additions & 10 deletions api/v1beta1/openstackdataplaneservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ type OpenstackDataPlaneServiceCert struct {

// OpenStackDataPlaneServiceSpec defines the desired state of OpenStackDataPlaneService
type OpenStackDataPlaneServiceSpec struct {
// Play is an inline playbook contents that ansible will run on execution.
Play string `json:"play,omitempty"`

// Playbook is a path to the playbook that ansible will run on this execution
Playbook string `json:"playbook,omitempty"`

// ConfigMaps list of ConfigMap names to mount as ExtraMounts for the OpenStackAnsibleEE
// +kubebuilder:validation:Optional
ConfigMaps []string `json:"configMaps,omitempty" yaml:"configMaps,omitempty"`
Expand All @@ -62,18 +56,24 @@ type OpenStackDataPlaneServiceSpec struct {
// +kubebuilder:validation:Optional
Secrets []string `json:"secrets,omitempty"`

// OpenStackAnsibleEERunnerImage image to use as the ansibleEE runner image
// +kubebuilder:validation:Optional
OpenStackAnsibleEERunnerImage string `json:"openStackAnsibleEERunnerImage,omitempty" yaml:"openStackAnsibleEERunnerImage,omitempty"`

// TLSCert tls certs to be generated
// +kubebuilder:validation:Optional
TLSCert *OpenstackDataPlaneServiceCert `json:"tlsCert,omitempty" yaml:"tlsCert,omitempty"`

// Play is an inline playbook contents that ansible will run on execution.
Play string `json:"play,omitempty"`

// Playbook is a path to the playbook that ansible will run on this execution
Playbook string `json:"playbook,omitempty"`

// CACerts - Secret containing the CA certificate chain
// +kubebuilder:validation:Optional
CACerts string `json:"caCerts,omitempty" yaml:"caCerts,omitempty"`

// OpenStackAnsibleEERunnerImage image to use as the ansibleEE runner image
// +kubebuilder:validation:Optional
OpenStackAnsibleEERunnerImage string `json:"openStackAnsibleEERunnerImage,omitempty" yaml:"openStackAnsibleEERunnerImage,omitempty"`

// AddCertMounts - Whether to add cert mounts
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Expand Down
Loading

0 comments on commit b124ce7

Please sign in to comment.