Skip to content

Commit 9082ab0

Browse files
committed
[release-0.10] Fix enabling of disabled bastion on upgrade to v1beta1
1 parent 6b2ab8a commit 9082ab0

File tree

7 files changed

+51
-9
lines changed

7 files changed

+51
-9
lines changed

api/v1alpha5/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/openstackcluster_conversion.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,10 @@ func restorev1beta1Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
478478

479479
optional.RestoreString(&(*previous).FloatingIP, &(*dst).FloatingIP)
480480
optional.RestoreString(&(*previous).AvailabilityZone, &(*dst).AvailabilityZone)
481-
optional.RestoreBool(&(*previous).Enabled, &(*dst).Enabled)
481+
482+
if (*dst).Enabled != nil && !*(*dst).Enabled {
483+
(*dst).Enabled = (*previous).Enabled
484+
}
482485
}
483486

484487
func Convert_v1alpha6_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Bastion, s apiconversion.Scope) error {

api/v1alpha6/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha7/openstackcluster_conversion.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ func restorev1beta1Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
416416
restorev1beta1MachineSpec((*previous).Spec, (*dst).Spec)
417417
optional.RestoreString(&(*previous).FloatingIP, &(*dst).FloatingIP)
418418
optional.RestoreString(&(*previous).AvailabilityZone, &(*dst).AvailabilityZone)
419-
optional.RestoreBool(&(*previous).Enabled, &(*dst).Enabled)
419+
420+
if (*dst).Enabled != nil && !*(*dst).Enabled {
421+
(*dst).Enabled = (*previous).Enabled
422+
}
420423
}
421424

422425
func Convert_v1alpha7_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Bastion, s apiconversion.Scope) error {

api/v1alpha7/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ type Bastion struct {
795795
// waiting until the bastion has been deleted.
796796
// +kubebuilder:default:=true
797797
// +optional
798-
Enabled optional.Bool `json:"enabled,omitempty"`
798+
Enabled *bool `json:"enabled,omitempty"`
799799

800800
// Spec for the bastion itself
801801
Spec *OpenStackMachineSpec `json:"spec,omitempty"`

test/e2e/suites/apivalidations/openstackcluster_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ var _ = Describe("OpenStackCluster API validations", func() {
215215
Expect(cluster.Spec.ControlPlaneEndpoint).To(Equal(*infrav1Cluster.Spec.ControlPlaneEndpoint), "Control plane endpoint should be restored")
216216
Expect(cluster.Spec.IdentityRef.Kind).To(Equal("FakeKind"), "IdentityRef.Kind should be restored")
217217
})
218+
219+
It("should not enable an explicitly disabled bastion when converting to v1beta1", func() {
220+
cluster.Spec.Bastion = &infrav1alpha7.Bastion{Enabled: false}
221+
Expect(create(cluster)).To(Succeed(), "OpenStackCluster creation should succeed")
222+
223+
// Fetch the infrav1 version of the cluster
224+
infrav1Cluster := &infrav1.OpenStackCluster{}
225+
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: cluster.Name, Namespace: cluster.Namespace}, infrav1Cluster)).To(Succeed(), "OpenStackCluster fetch should succeed")
226+
227+
infrav1Bastion := infrav1Cluster.Spec.Bastion
228+
229+
// NOTE(mdbooth): It may be reasonable to remove the
230+
// bastion if it is disabled with no other properties.
231+
// It would be reasonable to update the assertions
232+
// accordingly if we did that.
233+
Expect(infrav1Bastion).ToNot(BeNil(), "Bastion should not have been removed")
234+
Expect(infrav1Bastion.Enabled).To(Equal(ptr.To(false)), "Bastion should remain disabled")
235+
})
218236
})
219237

220238
Context("v1alpha6", func() {
@@ -252,5 +270,23 @@ var _ = Describe("OpenStackCluster API validations", func() {
252270
Expect(cluster.Spec.ControlPlaneEndpoint).To(Equal(*infrav1Cluster.Spec.ControlPlaneEndpoint), "Control plane endpoint should be restored")
253271
Expect(cluster.Spec.IdentityRef.Kind).To(Equal("FakeKind"), "IdentityRef.Kind should be restored")
254272
})
273+
274+
It("should not enable an explicitly disabled bastion when converting to v1beta1", func() {
275+
cluster.Spec.Bastion = &infrav1alpha6.Bastion{Enabled: false}
276+
Expect(create(cluster)).To(Succeed(), "OpenStackCluster creation should succeed")
277+
278+
// Fetch the infrav1 version of the cluster
279+
infrav1Cluster := &infrav1.OpenStackCluster{}
280+
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: cluster.Name, Namespace: cluster.Namespace}, infrav1Cluster)).To(Succeed(), "OpenStackCluster fetch should succeed")
281+
282+
infrav1Bastion := infrav1Cluster.Spec.Bastion
283+
284+
// NOTE(mdbooth): It may be reasonable to remove the
285+
// bastion if it is disabled with no other properties.
286+
// It would be reasonable to update the assertions
287+
// accordingly if we did that.
288+
Expect(infrav1Bastion).ToNot(BeNil(), "Bastion should not have been removed")
289+
Expect(infrav1Bastion.Enabled).To(Equal(ptr.To(false)), "Bastion should remain disabled")
290+
})
255291
})
256292
})

0 commit comments

Comments
 (0)