Skip to content

Commit

Permalink
Ownerref
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Sep 1, 2023
1 parent 4132e1b commit 05399c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
2 changes: 2 additions & 0 deletions internal/controllers/topology/cluster/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ func computeMachinePool(_ context.Context, s *scope.Scope, machinePoolTopology c
cluster: s.Current.Cluster,
namePrefix: bootstrapConfigNamePrefix(s.Current.Cluster.Name, machinePoolTopology.Name),
currentObjectRef: currentBootstrapConfigRef,
ownerRef: ownerReferenceTo(s.Current.Cluster),
})
if err != nil {
return nil, errors.Wrapf(err, "failed to compute bootstrap object for topology %q", machinePoolTopology.Name)
Expand All @@ -977,6 +978,7 @@ func computeMachinePool(_ context.Context, s *scope.Scope, machinePoolTopology c
cluster: s.Current.Cluster,
namePrefix: infrastructureMachinePoolNamePrefix(s.Current.Cluster.Name, machinePoolTopology.Name),
currentObjectRef: currentInfraMachinePoolRef,
ownerRef: ownerReferenceTo(s.Current.Cluster),
})
if err != nil {
return nil, errors.Wrapf(err, "failed to compute infrastructure object for topology %q", machinePoolTopology.Name)
Expand Down
30 changes: 16 additions & 14 deletions internal/controllers/topology/cluster/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ func TestComputeMachineDeployment(t *testing.T) {
}

func TestComputeMachinePool(t *testing.T) {
workerInfrastructureMachinePoolTemplate := builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "linux-worker-infraMachinePooltemplate").
workerInfrastructureMachinePoolTemplate := builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "linux-worker-inframachinepooltemplate").
Build()
workerBootstrapTemplate := builder.BootstrapTemplate(metav1.NamespaceDefault, "linux-worker-bootstraptemplate").
Build()
Expand All @@ -1739,6 +1739,7 @@ func TestComputeMachinePool(t *testing.T) {
WithAnnotations(annotations).
WithInfrastructureTemplate(workerInfrastructureMachinePoolTemplate).
WithBootstrapTemplate(workerBootstrapTemplate).
WithFailureDomains("A", "B").
WithNodeDrainTimeout(&clusterClassDuration).
WithNodeVolumeDetachTimeout(&clusterClassDuration).
WithNodeDeletionTimeout(&clusterClassDuration).
Expand Down Expand Up @@ -1777,7 +1778,7 @@ func TestComputeMachinePool(t *testing.T) {
}

replicas := int32(5)
topologyFailureDomain := "B"
topologyFailureDomains := []string{"A", "B"}
topologyDuration := metav1.Duration{Duration: 10 * time.Second}
var topologyMinReadySeconds int32 = 10
mpTopology := clusterv1.MachinePoolTopology{
Expand All @@ -1797,6 +1798,7 @@ func TestComputeMachinePool(t *testing.T) {
Class: "linux-worker",
Name: "big-pool-of-machines",
Replicas: &replicas,
FailureDomains: topologyFailureDomains,
NodeDrainTimeout: &topologyDuration,
NodeVolumeDetachTimeout: &topologyDuration,
NodeDeletionTimeout: &topologyDuration,
Expand Down Expand Up @@ -1828,13 +1830,13 @@ func TestComputeMachinePool(t *testing.T) {
actualMd := actual.Object
g.Expect(*actualMd.Spec.Replicas).To(Equal(replicas))
g.Expect(*actualMd.Spec.MinReadySeconds).To(Equal(topologyMinReadySeconds))
g.Expect(*actualMd.Spec.Template.Spec.FailureDomain).To(Equal(topologyFailureDomain))
g.Expect(*actualMd.Spec.Template.Spec.NodeDrainTimeout).To(Equal(topologyDuration))
g.Expect(*actualMd.Spec.Template.Spec.NodeVolumeDetachTimeout).To(Equal(topologyDuration))
g.Expect(*actualMd.Spec.Template.Spec.NodeDeletionTimeout).To(Equal(topologyDuration))
g.Expect(actualMd.Spec.ClusterName).To(Equal("cluster1"))
g.Expect(actualMd.Name).To(ContainSubstring("cluster1"))
g.Expect(actualMd.Name).To(ContainSubstring("big-pool-of-machines"))
g.Expect(actualMd.Spec.FailureDomains).To(Equal(topologyFailureDomains))

expectedAnnotations := util.MergeMap(mpTopology.Metadata.Annotations, mp1.Template.Metadata.Annotations)
delete(expectedAnnotations, clusterv1.ClusterTopologyHoldUpgradeSequenceAnnotation)
Expand All @@ -1854,7 +1856,7 @@ func TestComputeMachinePool(t *testing.T) {
})))

g.Expect(actualMd.Spec.Template.Spec.InfrastructureRef.Name).ToNot(Equal("linux-worker-inframachinetemplate"))
g.Expect(actualMd.Spec.Template.Spec.Bootstrap.ConfigRef.Name).ToNot(Equal("linux-worker-BootstrapObject"))
g.Expect(actualMd.Spec.Template.Spec.Bootstrap.ConfigRef.Name).ToNot(Equal("linux-worker-bootstraptemplate"))
})
t.Run("Generates the machine pool and the referenced templates using ClusterClass defaults", func(t *testing.T) {
g := NewWithT(t)
Expand Down Expand Up @@ -1916,31 +1918,31 @@ func TestComputeMachinePool(t *testing.T) {
actual, err := computeMachinePool(ctx, s, mpTopology)
g.Expect(err).ToNot(HaveOccurred())

actualMd := actual.Object
actualMp := actual.Object

g.Expect(*actualMd.Spec.Replicas).NotTo(Equal(currentReplicas))
g.Expect(*actualMd.Spec.Template.Spec.FailureDomain).To(Equal(topologyFailureDomain))
g.Expect(actualMd.Name).To(Equal("existing-Pool-1"))
g.Expect(*actualMp.Spec.Replicas).NotTo(Equal(currentReplicas))
g.Expect(actualMp.Spec.FailureDomains).To(Equal(topologyFailureDomains))
g.Expect(actualMp.Name).To(Equal("existing-pool-1"))

expectedAnnotations := util.MergeMap(mpTopology.Metadata.Annotations, mp1.Template.Metadata.Annotations)
delete(expectedAnnotations, clusterv1.ClusterTopologyHoldUpgradeSequenceAnnotation)
delete(expectedAnnotations, clusterv1.ClusterTopologyDeferUpgradeAnnotation)
g.Expect(actualMd.Annotations).To(Equal(expectedAnnotations))
g.Expect(actualMd.Spec.Template.ObjectMeta.Annotations).To(Equal(expectedAnnotations))
g.Expect(actualMp.Annotations).To(Equal(expectedAnnotations))
g.Expect(actualMp.Spec.Template.ObjectMeta.Annotations).To(Equal(expectedAnnotations))

g.Expect(actualMd.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{
g.Expect(actualMp.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachinePoolNameLabel: "big-pool-of-machines",
})))
g.Expect(actualMd.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{
g.Expect(actualMp.Spec.Template.ObjectMeta.Labels).To(BeComparableTo(util.MergeMap(mpTopology.Metadata.Labels, mp1.Template.Metadata.Labels, map[string]string{
clusterv1.ClusterNameLabel: cluster.Name,
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachinePoolNameLabel: "big-pool-of-machines",
})))

g.Expect(actualMd.Spec.Template.Spec.InfrastructureRef.Name).To(Equal("linux-worker-inframachinetemplate"))
g.Expect(actualMd.Spec.Template.Spec.Bootstrap.ConfigRef.Name).To(Equal("linux-worker-BootstrapObject"))
g.Expect(actualMp.Spec.Template.Spec.InfrastructureRef.Name).To(Equal("linux-worker-inframachinepooltemplate"))
g.Expect(actualMp.Spec.Template.Spec.Bootstrap.ConfigRef.Name).To(Equal("linux-worker-bootstrapobject"))
})

t.Run("If a machine pool references a topology class that does not exist, machine pool generation fails", func(t *testing.T) {
Expand Down

0 comments on commit 05399c9

Please sign in to comment.