Skip to content

Commit

Permalink
Extend Deployment/Pool builtin to include metadata
Browse files Browse the repository at this point in the history
This patch extends the MachineDeployment and MachinePool builtins to
include metadata.

Signed-off-by: Sagar Muchhal <muchhals@vmware.com>
  • Loading branch information
srm09 committed Jul 8, 2024
1 parent 0cdfb88 commit 154d4a0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package v1alpha1

import "k8s.io/apimachinery/pkg/types"
import (
"k8s.io/apimachinery/pkg/types"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// BuiltinsName is the name of the builtin variable.
const BuiltinsName = "builtin"
Expand Down Expand Up @@ -116,6 +120,9 @@ type MachineDeploymentBuiltins struct {
// being orchestrated.
Version string `json:"version,omitempty"`

// Metadata is the additional metadata set on the MachineDeployment
Metadata *clusterv1.ObjectMeta `json:"metadata,omitempty"`

// Class is the class name of the MachineDeployment,
// to which the current template belongs to.
Class string `json:"class,omitempty"`
Expand Down Expand Up @@ -149,6 +156,9 @@ type MachinePoolBuiltins struct {
// being orchestrated.
Version string `json:"version,omitempty"`

// Metadata is the additional metadata set on the MachinePool.
Metadata *clusterv1.ObjectMeta `json:"metadata,omitempty"`

// Class is the class name of the MachinePool,
// to which the current template belongs to.
Class string `json:"class,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go

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

16 changes: 14 additions & 2 deletions exp/runtime/hooks/api/v1alpha1/zz_generated.openapi.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ func MachineDeployment(mdTopology *clusterv1.MachineDeploymentTopology, md *clus
if md.Spec.Replicas != nil {
builtin.MachineDeployment.Replicas = ptr.To[int64](int64(*md.Spec.Replicas))
}
if mdTopology.Metadata.Labels != nil || mdTopology.Metadata.Annotations != nil {
metadata := &clusterv1.ObjectMeta{}
if mdTopology.Metadata.Labels != nil {
metadata.Labels = mdTopology.Metadata.Labels
}
if mdTopology.Metadata.Annotations != nil {
metadata.Annotations = mdTopology.Metadata.Annotations
}
builtin.MachineDeployment.Metadata = metadata
}

if mdBootstrapTemplate != nil {
builtin.MachineDeployment.Bootstrap = &runtimehooksv1.MachineBootstrapBuiltins{
Expand Down Expand Up @@ -235,6 +245,16 @@ func MachinePool(mpTopology *clusterv1.MachinePoolTopology, mp *expv1.MachinePoo
if mp.Spec.Replicas != nil {
builtin.MachinePool.Replicas = ptr.To[int64](int64(*mp.Spec.Replicas))
}
if mpTopology.Metadata.Labels != nil || mpTopology.Metadata.Annotations != nil {
metadata := &clusterv1.ObjectMeta{}
if mpTopology.Metadata.Labels != nil {
metadata.Labels = mpTopology.Metadata.Labels
}
if mpTopology.Metadata.Annotations != nil {
metadata.Annotations = mpTopology.Metadata.Annotations
}
builtin.MachinePool.Metadata = metadata
}

if mpBootstrapObject != nil {
builtin.MachinePool.Bootstrap = &runtimehooksv1.MachineBootstrapBuiltins{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ func TestMachineDeployment(t *testing.T) {
Replicas: ptr.To[int32](3),
Name: "md-topology",
Class: "md-class",
Metadata: clusterv1.ObjectMeta{
Labels: map[string]string{"foo": "bar"},
Annotations: map[string]string{"fizz": "buzz"},
},
Variables: &clusterv1.MachineDeploymentVariables{
Overrides: []clusterv1.ClusterVariable{
{
Expand Down Expand Up @@ -699,6 +703,7 @@ func TestMachineDeployment(t *testing.T) {
Value: toJSONCompact(`{
"machineDeployment":{
"version": "v1.21.1",
"metadata": {"labels":{"foo":"bar"}, "annotations":{"fizz":"buzz"}},
"class": "md-class",
"name": "md1",
"topologyName": "md-topology",
Expand Down Expand Up @@ -1035,6 +1040,10 @@ func TestMachinePool(t *testing.T) {
Replicas: ptr.To[int32](3),
Name: "mp-topology",
Class: "mp-class",
Metadata: clusterv1.ObjectMeta{
Labels: map[string]string{"foo": "bar"},
Annotations: map[string]string{"fizz": "buzz"},
},
Variables: &clusterv1.MachinePoolVariables{
Overrides: []clusterv1.ClusterVariable{
{
Expand Down Expand Up @@ -1066,6 +1075,7 @@ func TestMachinePool(t *testing.T) {
Value: toJSONCompact(`{
"machinePool":{
"version": "v1.21.1",
"metadata": {"labels":{"foo":"bar"}, "annotations":{"fizz":"buzz"}},
"class": "mp-class",
"name": "mp1",
"topologyName": "mp-topology",
Expand Down

0 comments on commit 154d4a0

Please sign in to comment.