Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/local/vmoperator/local_env_var_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ spec:
value: "true"
- name: MEM_STATS_PERIOD
value: "10m"
- name: FAST_DEPLOY_MODE
value: ""
- name: PROMOTE_DISKS_MODE
value: ""
- name: VSPHERE_NETWORKING
value: "false"
- name: FSS_WCP_INSTANCE_STORAGE
Expand Down
12 changes: 12 additions & 0 deletions config/wcp/vmoperator/manager_env_var_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
name: MEM_STATS_PERIOD
value: "10m"

- op: add
path: /spec/template/spec/containers/0/env/-
value:
name: FAST_DEPLOY_MODE
value: ""

- op: add
path: /spec/template/spec/containers/0/env/-
value:
name: PROMOTE_DISKS_MODE
value: ""

- op: add
path: /spec/template/spec/containers/0/env/-
value:
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Config struct {
// Defaults to "direct".
FastDeployMode string

// PromoteDisksMode determines the default mode for disk promotion.
PromoteDisksMode string

// VCCredsSecretName is the name of the secret in the pod namespace that
// contains the VC credentials.
//
Expand Down
1 change: 1 addition & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Default() Config {
AsyncCreateEnabled: true,
MemStatsPeriod: 10 * time.Minute,
FastDeployMode: pkgconst.FastDeployModeLinked,
PromoteDisksMode: "",
VCCredsSecretName: pkgconst.VCCredsSecretName,
CreateVMRequeueDelay: 10 * time.Second,
PoweredOnVMHasIPRequeueDelay: 10 * time.Second,
Expand Down
1 change: 1 addition & 0 deletions pkg/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func FromEnv() Config {
setBool(env.AsyncCreateEnabled, &config.AsyncCreateEnabled)
setDuration(env.MemStatsPeriod, &config.MemStatsPeriod)
setString(env.FastDeployMode, &config.FastDeployMode)
setString(env.PromoteDisksMode, &config.PromoteDisksMode)
setString(env.VCCredsSecretName, &config.VCCredsSecretName)

setDuration(env.InstanceStoragePVPlacementFailedTTL, &config.InstanceStorage.PVPlacementFailedTTL)
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
AsyncSignalEnabled
AsyncCreateEnabled
FastDeployMode
PromoteDisksMode
VCCredsSecretName
InstanceStoragePVPlacementFailedTTL
InstanceStorageJitterMaxFactor
Expand Down Expand Up @@ -117,6 +118,8 @@ func (n VarName) String() string {
return "ASYNC_CREATE_ENABLED"
case FastDeployMode:
return "FAST_DEPLOY_MODE"
case PromoteDisksMode:
return "PROMOTE_DISKS_MODE"
case VCCredsSecretName:
return "VC_CREDS_SECRET_NAME"
case InstanceStoragePVPlacementFailedTTL:
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ var _ = Describe(
Expect(os.Setenv("SYNC_IMAGE_REQUEUE_DELAY", "128h")).To(Succeed())
Expect(os.Setenv("DEPLOYMENT_NAME", "129")).To(Succeed())
Expect(os.Setenv("SIGUSR2_RESTART_ENABLED", "true")).To(Succeed())
Expect(os.Setenv("PROMOTE_DISKS_MODE", "130")).To(Succeed())
})
It("Should return a default config overridden by the environment", func() {
Expect(config).To(BeComparableTo(pkgcfg.Config{
Expand Down Expand Up @@ -163,6 +164,7 @@ var _ = Describe(
SyncImageRequeueDelay: 128 * time.Hour,
DeploymentName: "129",
SIGUSR2RestartEnabled: true,
PromoteDisksMode: "130",
}))
})
})
Expand Down
36 changes: 33 additions & 3 deletions pkg/vmconfig/diskpromo/diskpromo_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha4"
pkgcond "github.com/vmware-tanzu/vm-operator/pkg/conditions"
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
pkgerr "github.com/vmware-tanzu/vm-operator/pkg/errors"
pkgutil "github.com/vmware-tanzu/vm-operator/pkg/util"
Expand Down Expand Up @@ -141,11 +142,40 @@ func (r reconciler) Reconcile(
}
}

logger = logger.WithValues("mode", vm.Spec.PromoteDisksMode)
const defaultMode = vmopv1.VirtualMachinePromoteDisksModeOnline

promoMode := vm.Spec.PromoteDisksMode
if promoMode == "" {
// Default to online promote.
promoMode = defaultMode
logger.Info("Empty promotion mode, using default mode",
"defaultMode", defaultMode)
}

// Allow the mode to be overridden via an env var.
if v := pkgcfg.FromContext(ctx).PromoteDisksMode; v != "" {
promoMode = vmopv1.VirtualMachinePromoteDisksMode(v)
logger.Info("Got promo mode from env", "mode", promoMode)
}

// Validate the promotion mode.
switch promoMode {
case vmopv1.VirtualMachinePromoteDisksModeOnline,
vmopv1.VirtualMachinePromoteDisksModeOffline,
vmopv1.VirtualMachinePromoteDisksModeDisabled:
// No-op
default:
logger.Info("Invalid promotion mode, using default mode",
"invalidMode", promoMode,
"defaultMode", defaultMode)
promoMode = defaultMode
}

logger = logger.WithValues("mode", promoMode)

logger.V(4).Info("Finding candidates for disk promotion")

if vm.Spec.PromoteDisksMode == vmopv1.VirtualMachinePromoteDisksModeDisabled {
if promoMode == vmopv1.VirtualMachinePromoteDisksModeDisabled {
// Skip VMs that do not request promotion.
pkgcond.Delete(vm, vmopv1.VirtualMachineDiskPromotionSynced)
return nil
Expand Down Expand Up @@ -221,7 +251,7 @@ func (r reconciler) Reconcile(
return nil
}

switch vm.Spec.PromoteDisksMode {
switch promoMode {
case vmopv1.VirtualMachinePromoteDisksModeOnline:
if moVM.Snapshot != nil && moVM.Snapshot.CurrentSnapshot != nil {
// Skip VMs that have snapshots.
Expand Down
15 changes: 15 additions & 0 deletions pkg/vmconfig/diskpromo/diskpromo_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ var _ = Describe("Reconcile", Label(testlabels.V1Alpha4), func() {
Expect(r.Reconcile(ctx, k8sClient, vimClient, vm, moVM, configSpec)).To(Succeed())
})

When("mode is overridden to Offline via env var", func() {
BeforeEach(func() {
pkgcfg.SetContext(ctx, func(config *pkgcfg.Config) {
config.PromoteDisksMode = "Offline"
})
})
It("should not promote disks", func() {
Expect(err).ToNot(HaveOccurred())
c := conditions.Get(vm, vmopv1.VirtualMachineDiskPromotionSynced)
Expect(c).ToNot(BeNil())
Expect(c.Status).To(Equal(metav1.ConditionFalse))
Expect(c.Reason).To(Equal(diskpromo.ReasonPending))
})
})

When("VM has a snapshot after disks were promoted", func() {
It("should not mark the disk promotion synced as false since disks with snapshots are ignored", func() {
Expect(err).To(HaveOccurred())
Expand Down