Skip to content

Commit dfe9148

Browse files
committed
Revert "✨ Persist VM's kubernetes and bootstrap data in ExtraConfig (vmware-tanzu#213)"
This reverts commit e552bc9.
1 parent d227001 commit dfe9148

20 files changed

+53
-349
lines changed

controllers/virtualmachine/v1alpha1/virtualmachine_controller.go

-9
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,6 @@ func (r *Reconciler) ReconcileNormal(ctx *context.VirtualMachineContext) (reterr
472472
// Add this VM to prober manager if ReconcileNormal succeeds.
473473
r.Prober.AddToProberManager(ctx.VM)
474474

475-
// Back up this VM if ReconcileNormal succeeds and the FSS is enabled.
476-
if lib.IsVMServiceBackupRestoreFSSEnabled() {
477-
if err := r.VMProvider.BackupVirtualMachine(ctx, ctx.VM); err != nil {
478-
ctx.Logger.Error(err, "Failed to backup VirtualMachine")
479-
r.Recorder.EmitEvent(ctx.VM, "Backup", err, false)
480-
return err
481-
}
482-
}
483-
484475
ctx.Logger.Info("Finished Reconciling VirtualMachine")
485476
return nil
486477
}

controllers/virtualmachine/v1alpha1/virtualmachine_controller_unit_test.go

+1-24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright (c) 2019-2023 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2019-2021 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package v1alpha1_test
55

66
import (
77
"context"
88
"errors"
9-
"os"
109
"strings"
1110

1211
. "github.com/onsi/ginkgo"
@@ -19,7 +18,6 @@ import (
1918

2019
virtualmachine "github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/v1alpha1"
2120
vmopContext "github.com/vmware-tanzu/vm-operator/pkg/context"
22-
"github.com/vmware-tanzu/vm-operator/pkg/lib"
2321
proberfake "github.com/vmware-tanzu/vm-operator/pkg/prober/fake"
2422
providerfake "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake"
2523
"github.com/vmware-tanzu/vm-operator/test/builder"
@@ -156,27 +154,6 @@ func unitTestsReconcile() {
156154
Expect(reconciler.ReconcileNormal(vmCtx)).Should(Succeed())
157155
Expect(fakeProbeManager.IsAddToProberManagerCalled).Should(BeTrue())
158156
})
159-
160-
When("The VM Service Backup and Restore FSS is enabled", func() {
161-
BeforeEach(func() {
162-
Expect(os.Setenv(lib.VMServiceBackupRestoreFSS, lib.TrueString)).To(Succeed())
163-
})
164-
165-
AfterEach(func() {
166-
Expect(os.Unsetenv(lib.VMServiceBackupRestoreFSS)).To(Succeed())
167-
})
168-
169-
It("Should call backup Virtual Machine if ReconcileNormal succeeds", func() {
170-
var isBackupVirtualMachineCalled bool
171-
fakeVMProvider.BackupVirtualMachineFn = func(ctx context.Context, vm *vmopv1.VirtualMachine) error {
172-
isBackupVirtualMachineCalled = true
173-
return nil
174-
}
175-
176-
Expect(reconciler.ReconcileNormal(vmCtx)).Should(Succeed())
177-
Expect(isBackupVirtualMachineCalled).Should(BeTrue())
178-
})
179-
})
180157
})
181158

182159
Context("ReconcileDelete", func() {

controllers/virtualmachine/v1alpha2/virtualmachine_controller.go

-9
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,6 @@ func (r *Reconciler) ReconcileNormal(ctx *context.VirtualMachineContextA2) (rete
337337
// Add this VM to prober manager if ReconcileNormal succeeds.
338338
r.Prober.AddToProberManager(ctx.VM)
339339

340-
// Back up this VM if ReconcileNormal succeeds and the FSS is enabled.
341-
if lib.IsVMServiceBackupRestoreFSSEnabled() {
342-
if err := r.VMProvider.BackupVirtualMachine(ctx, ctx.VM); err != nil {
343-
ctx.Logger.Error(err, "Failed to backup VirtualMachine")
344-
r.Recorder.EmitEvent(ctx.VM, "Backup", err, false)
345-
return err
346-
}
347-
}
348-
349340
ctx.Logger.Info("Finished Reconciling VirtualMachine")
350341
return nil
351342
}

controllers/virtualmachine/v1alpha2/virtualmachine_controller_unit_test.go

-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package v1alpha2_test
66
import (
77
"context"
88
"errors"
9-
"os"
109
"strings"
1110

1211
. "github.com/onsi/ginkgo"
@@ -19,7 +18,6 @@ import (
1918

2019
virtualmachine "github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/v1alpha2"
2120
vmopContext "github.com/vmware-tanzu/vm-operator/pkg/context"
22-
"github.com/vmware-tanzu/vm-operator/pkg/lib"
2321
proberfake "github.com/vmware-tanzu/vm-operator/pkg/prober2/fake"
2422
providerfake "github.com/vmware-tanzu/vm-operator/pkg/vmprovider/fake"
2523
"github.com/vmware-tanzu/vm-operator/test/builder"
@@ -155,27 +153,6 @@ func unitTestsReconcile() {
155153
Expect(reconciler.ReconcileNormal(vmCtx)).Should(Succeed())
156154
Expect(fakeProbeManager.IsAddToProberManagerCalled).Should(BeTrue())
157155
})
158-
159-
When("The VM Service Backup and Restore FSS is enabled", func() {
160-
BeforeEach(func() {
161-
Expect(os.Setenv(lib.VMServiceBackupRestoreFSS, lib.TrueString)).To(Succeed())
162-
})
163-
164-
AfterEach(func() {
165-
Expect(os.Unsetenv(lib.VMServiceBackupRestoreFSS)).To(Succeed())
166-
})
167-
168-
It("Should call backup Virtual Machine if ReconcileNormal succeeds", func() {
169-
var isBackupVirtualMachineCalled bool
170-
fakeVMProvider.BackupVirtualMachineFn = func(ctx context.Context, vm *vmopv1.VirtualMachine) error {
171-
isBackupVirtualMachineCalled = true
172-
return nil
173-
}
174-
175-
Expect(reconciler.ReconcileNormal(vmCtx)).Should(Succeed())
176-
Expect(isBackupVirtualMachineCalled).Should(BeTrue())
177-
})
178-
})
179156
})
180157

181158
Context("ReconcileDelete", func() {

pkg/lib/env.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
const (
16+
trueString = "true"
1617
TrueString = "true"
1718
VmopNamespaceEnv = "POD_NAMESPACE"
1819
WcpFaultDomainsFSS = "FSS_WCP_FAULTDOMAINS"
@@ -92,43 +93,43 @@ func GetNetworkProviderType() string {
9293
}
9394

9495
var IsWcpFaultDomainsFSSEnabled = func() bool {
95-
return os.Getenv(WcpFaultDomainsFSS) == TrueString
96+
return os.Getenv(WcpFaultDomainsFSS) == trueString
9697
}
9798

9899
func IsVMServiceV1Alpha2FSSEnabled() bool {
99-
return os.Getenv(VMServiceV1Alpha2FSS) == TrueString
100+
return os.Getenv(VMServiceV1Alpha2FSS) == trueString
100101
}
101102

102103
var IsInstanceStorageFSSEnabled = func() bool {
103-
return os.Getenv(InstanceStorageFSS) == TrueString
104+
return os.Getenv(InstanceStorageFSS) == trueString
104105
}
105106

106107
var IsUnifiedTKGFSSEnabled = func() bool {
107-
return os.Getenv(UnifiedTKGFSS) == TrueString
108+
return os.Getenv(UnifiedTKGFSS) == trueString
108109
}
109110

110111
var IsVMClassAsConfigFSSEnabled = func() bool {
111-
return os.Getenv(VMClassAsConfigFSS) == TrueString
112+
return os.Getenv(VMClassAsConfigFSS) == trueString
112113
}
113114

114115
var IsVMClassAsConfigFSSDaynDateEnabled = func() bool {
115-
return os.Getenv(VMClassAsConfigDaynDateFSS) == TrueString
116+
return os.Getenv(VMClassAsConfigDaynDateFSS) == trueString
116117
}
117118

118119
var IsWCPVMImageRegistryEnabled = func() bool {
119-
return os.Getenv(VMImageRegistryFSS) == TrueString
120+
return os.Getenv(VMImageRegistryFSS) == trueString
120121
}
121122

122123
var IsNamespacedVMClassFSSEnabled = func() bool {
123-
return os.Getenv(NamespacedVMClassFSS) == TrueString
124+
return os.Getenv(NamespacedVMClassFSS) == trueString
124125
}
125126

126127
var IsWindowsSysprepFSSEnabled = func() bool {
127-
return os.Getenv(WindowsSysprepFSS) == TrueString
128+
return os.Getenv(WindowsSysprepFSS) == trueString
128129
}
129130

130131
var IsVMServiceBackupRestoreFSSEnabled = func() bool {
131-
return os.Getenv(VMServiceBackupRestoreFSS) == TrueString
132+
return os.Getenv(VMServiceBackupRestoreFSS) == trueString
132133
}
133134

134135
// MaxConcurrentCreateVMsOnProvider returns the percentage of reconciler

pkg/util/enc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2022 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package util

pkg/util/enc_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2022 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package util_test
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"compress/gzip"
99
"encoding/base64"
10+
1011
. "github.com/onsi/ginkgo"
1112
. "github.com/onsi/gomega"
1213

@@ -152,6 +153,7 @@ var _ = Describe("TryToDecodeBase64Gzip", func() {
152153
})
153154
})
154155
})
156+
155157
Context("EncodeGzipBase64", func() {
156158
It("Encodes a string correctly", func() {
157159
input := "HelloWorld"

pkg/vmprovider/fake/fake_vm_provider.go

-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type funcs struct {
3131
DeleteVirtualMachineFn func(ctx context.Context, vm *vmopv1.VirtualMachine) error
3232
PublishVirtualMachineFn func(ctx context.Context, vm *vmopv1.VirtualMachine,
3333
vmPub *vmopv1.VirtualMachinePublishRequest, cl *imgregv1a1.ContentLibrary, actID string) (string, error)
34-
BackupVirtualMachineFn func(ctx context.Context, vm *vmopv1.VirtualMachine) error
3534
GetVirtualMachineGuestHeartbeatFn func(ctx context.Context, vm *vmopv1.VirtualMachine) (vmopv1.GuestHeartbeatStatus, error)
3635
GetVirtualMachineWebMKSTicketFn func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error)
3736
GetVirtualMachineHardwareVersionFn func(ctx context.Context, vm *vmopv1.VirtualMachine) (int32, error)
@@ -113,17 +112,6 @@ func (s *VMProvider) PublishVirtualMachine(ctx context.Context, vm *vmopv1.Virtu
113112
return "dummy-id", nil
114113
}
115114

116-
func (s *VMProvider) BackupVirtualMachine(ctx context.Context, vm *vmopv1.VirtualMachine) error {
117-
s.Lock()
118-
defer s.Unlock()
119-
120-
if s.BackupVirtualMachineFn != nil {
121-
return s.BackupVirtualMachineFn(ctx, vm)
122-
}
123-
124-
return nil
125-
}
126-
127115
func (s *VMProvider) GetVirtualMachineGuestHeartbeat(ctx context.Context, vm *vmopv1.VirtualMachine) (vmopv1.GuestHeartbeatStatus, error) {
128116
s.Lock()
129117
defer s.Unlock()

pkg/vmprovider/fake/fake_vm_provider_a2.go

-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type funcsA2 struct {
3131
DeleteVirtualMachineFn func(ctx context.Context, vm *vmopv1.VirtualMachine) error
3232
PublishVirtualMachineFn func(ctx context.Context, vm *vmopv1.VirtualMachine,
3333
vmPub *vmopv1.VirtualMachinePublishRequest, cl *imgregv1a1.ContentLibrary, actID string) (string, error)
34-
BackupVirtualMachineFn func(ctx context.Context, vm *vmopv1.VirtualMachine) error
3534
GetVirtualMachineGuestHeartbeatFn func(ctx context.Context, vm *vmopv1.VirtualMachine) (vmopv1.GuestHeartbeatStatus, error)
3635
GetVirtualMachineWebMKSTicketFn func(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error)
3736
GetVirtualMachineHardwareVersionFn func(ctx context.Context, vm *vmopv1.VirtualMachine) (int32, error)
@@ -113,17 +112,6 @@ func (s *VMProviderA2) PublishVirtualMachine(ctx context.Context, vm *vmopv1.Vir
113112
return "dummy-id", nil
114113
}
115114

116-
func (s *VMProviderA2) BackupVirtualMachine(ctx context.Context, vm *vmopv1.VirtualMachine) error {
117-
s.Lock()
118-
defer s.Unlock()
119-
120-
if s.BackupVirtualMachineFn != nil {
121-
return s.BackupVirtualMachineFn(ctx, vm)
122-
}
123-
124-
return nil
125-
}
126-
127115
func (s *VMProviderA2) GetVirtualMachineGuestHeartbeat(ctx context.Context, vm *vmopv1.VirtualMachine) (vmopv1.GuestHeartbeatStatus, error) {
128116
s.Lock()
129117
defer s.Unlock()

pkg/vmprovider/interface.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type VirtualMachineProviderInterface interface {
2222
DeleteVirtualMachine(ctx context.Context, vm *vmopv1.VirtualMachine) error
2323
PublishVirtualMachine(ctx context.Context, vm *vmopv1.VirtualMachine,
2424
vmPub *vmopv1.VirtualMachinePublishRequest, cl *imgregv1a1.ContentLibrary, actID string) (string, error)
25-
BackupVirtualMachine(ctx context.Context, vm *vmopv1.VirtualMachine) error
2625
GetVirtualMachineGuestHeartbeat(ctx context.Context, vm *vmopv1.VirtualMachine) (vmopv1.GuestHeartbeatStatus, error)
2726
GetVirtualMachineWebMKSTicket(ctx context.Context, vm *vmopv1.VirtualMachine, pubKey string) (string, error)
2827
GetVirtualMachineHardwareVersion(ctx context.Context, vm *vmopv1.VirtualMachine) (int32, error)

pkg/vmprovider/interface_a2.go

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type VirtualMachineProviderInterfaceA2 interface {
2121
DeleteVirtualMachine(ctx context.Context, vm *v1alpha2.VirtualMachine) error
2222
PublishVirtualMachine(ctx context.Context, vm *v1alpha2.VirtualMachine,
2323
vmPub *v1alpha2.VirtualMachinePublishRequest, cl *imgregv1a1.ContentLibrary, actID string) (string, error)
24-
BackupVirtualMachine(ctx context.Context, vm *v1alpha2.VirtualMachine) error
2524
GetVirtualMachineGuestHeartbeat(ctx context.Context, vm *v1alpha2.VirtualMachine) (v1alpha2.GuestHeartbeatStatus, error)
2625
GetVirtualMachineWebMKSTicket(ctx context.Context, vm *v1alpha2.VirtualMachine, pubKey string) (string, error)
2726
GetVirtualMachineHardwareVersion(ctx context.Context, vm *v1alpha2.VirtualMachine) (int32, error)

pkg/vmprovider/providers/vsphere/constants/constants.go

-7
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,4 @@ const (
118118
V1alpha1SubnetMask = "V1alpha1_SubnetMask"
119119
// V1alpha1FormatNameservers is an alias for versioned templating function V1alpha1_FormatNameservers.
120120
V1alpha1FormatNameservers = "V1alpha1_FormatNameservers"
121-
122-
// BackupVMKubeDataExtraConfigKey is the ExtraConfig key to the VirtualMachine
123-
// resource's Kubernetes spec data, compressed using gzip and base64-encoded.
124-
BackupVMKubeDataExtraConfigKey = "vmservice.virtualmachine.kubedata"
125-
// BackupVMBootstrapDataExtraConfigKey is the ExtraConfig key to the VM's
126-
// bootstrap data object, compressed using gzip and base64-encoded.
127-
BackupVMBootstrapDataExtraConfigKey = "vmservice.virtualmachine.bootstrapdata"
128121
)

pkg/vmprovider/providers/vsphere/session/session_util.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
// Copyright (c) 2018-2023 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2018-2022 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package session
55

66
import (
7+
"bytes"
8+
"compress/gzip"
9+
"encoding/base64"
10+
711
vimTypes "github.com/vmware/govmomi/vim25/types"
812
)
913

@@ -77,3 +81,20 @@ func GetMergedvAppConfigSpec(inProps map[string]string, vmProps []vimTypes.VAppP
7781
OvfEnvironmentTransport: []string{OvfEnvironmentTransportGuestInfo},
7882
}
7983
}
84+
85+
func EncodeGzipBase64(s string) (string, error) {
86+
var zbuf bytes.Buffer
87+
zw := gzip.NewWriter(&zbuf)
88+
if _, err := zw.Write([]byte(s)); err != nil {
89+
return "", err
90+
}
91+
if err := zw.Flush(); err != nil {
92+
return "", err
93+
}
94+
if err := zw.Close(); err != nil {
95+
return "", err
96+
}
97+
98+
b64 := base64.StdEncoding.EncodeToString(zbuf.Bytes())
99+
return b64, nil
100+
}

pkg/vmprovider/providers/vsphere/session/session_util_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019-2023 VMware, Inc. All Rights Reserved.
1+
// Copyright (c) 2019-2022 VMware, Inc. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package session_test
@@ -156,4 +156,13 @@ var _ = Describe("Test Session Utils", func() {
156156
})
157157
})
158158
})
159+
160+
Context("EncodeGzipBase64", func() {
161+
It("Encodes a string correctly", func() {
162+
input := "HelloWorld"
163+
output, err := session.EncodeGzipBase64(input)
164+
Expect(err).ShouldNot(HaveOccurred())
165+
Expect(output).To(Equal("H4sIAAAAAAAA//JIzcnJD88vykkBAAAA//8BAAD//3kMd3cKAAAA"))
166+
})
167+
})
159168
})

pkg/vmprovider/providers/vsphere/session/session_vm_customization.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func GetCloudInitGuestInfoCustSpec(
157157

158158
extraConfig := map[string]string{}
159159

160-
encodedMetadata, err := util.EncodeGzipBase64(cloudInitMetadata)
160+
encodedMetadata, err := EncodeGzipBase64(cloudInitMetadata)
161161
if err != nil {
162162
return nil, fmt.Errorf("encoding cloud-init metadata failed %v", err)
163163
}
@@ -182,7 +182,7 @@ func GetCloudInitGuestInfoCustSpec(
182182
return nil, fmt.Errorf("decoding cloud-init userdata failed %v", err)
183183
}
184184

185-
encodedUserdata, err := util.EncodeGzipBase64(plainText)
185+
encodedUserdata, err := EncodeGzipBase64(plainText)
186186
if err != nil {
187187
return nil, fmt.Errorf("encoding cloud-init userdata failed %v", err)
188188
}

pkg/vmprovider/providers/vsphere/session/session_vm_customization_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha1"
2525

2626
"github.com/vmware-tanzu/vm-operator/pkg/context"
27-
"github.com/vmware-tanzu/vm-operator/pkg/util"
2827
"github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/constants"
2928
"github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/internal"
3029
"github.com/vmware-tanzu/vm-operator/pkg/vmprovider/providers/vsphere/network"
@@ -354,7 +353,7 @@ var _ = Describe("Cloud-Init Customization", func() {
354353

355354
Context("With gzipped, base64-encoded userdata but no encoding specified", func() {
356355
BeforeEach(func() {
357-
data, err := util.EncodeGzipBase64(cloudInitUserdata)
356+
data, err := session.EncodeGzipBase64(cloudInitUserdata)
358357
Expect(err).ToNot(HaveOccurred())
359358
updateArgs.VMMetadata.Data["user-data"] = data
360359
})
@@ -461,7 +460,7 @@ var _ = Describe("Cloud-Init Customization", func() {
461460

462461
Context("With gzipped, base64-encoded userdata but no encoding specified", func() {
463462
BeforeEach(func() {
464-
data, err := util.EncodeGzipBase64(cloudInitUserdata)
463+
data, err := session.EncodeGzipBase64(cloudInitUserdata)
465464
Expect(err).ToNot(HaveOccurred())
466465
updateArgs.VMMetadata.Data["user-data"] = data
467466
})

0 commit comments

Comments
 (0)