Skip to content

Commit

Permalink
Added vSphere support for additional disks
Browse files Browse the repository at this point in the history
  • Loading branch information
vr4manta committed Sep 18, 2024
1 parent 2a8e19b commit f1a2ff8
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 89 deletions.
4 changes: 2 additions & 2 deletions cmd/machineset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func main() {

// Sets up feature gates
defaultMutableGate := feature.DefaultMutableFeatureGate
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration, apifeatures.FeatureGateVSphereMultiDisk)
if err != nil {
klog.Fatalf("Error setting up feature gates: %v", err)
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func main() {
log.Fatal(err)
}

machineValidator, err := mapiwebhooks.NewMachineValidator(mgr.GetClient())
machineValidator, err := mapiwebhooks.NewMachineValidator(mgr.GetClient(), defaultMutableGate)
if err != nil {
log.Fatal(err)
}
Expand Down
17 changes: 10 additions & 7 deletions cmd/vsphere/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func main() {

// Sets up feature gates
defaultMutableGate := feature.DefaultMutableFeatureGate
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration)
gateOpts, err := features.NewFeatureGateOptions(defaultMutableGate, apifeatures.SelfManaged, apifeatures.FeatureGateVSphereStaticIPs, apifeatures.FeatureGateMachineAPIMigration, apifeatures.FeatureGateVSphereMultiDisk)
if err != nil {
klog.Fatalf("Error setting up feature gates: %v", err)
}
Expand Down Expand Up @@ -159,6 +159,9 @@ func main() {
staticIPFeatureGateEnabled := defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateVSphereStaticIPs))
klog.Infof("FeatureGateVSphereStaticIPs initialised: %t", staticIPFeatureGateEnabled)

multiDiskFeatureGateEnabled := defaultMutableGate.Enabled(featuregate.Feature(apifeatures.FeatureGateVSphereMultiDisk))
klog.Infof("FeatureGateVSphereMultiDisk initialised: %t", multiDiskFeatureGateEnabled)

// Setup a Manager
mgr, err := manager.New(cfg, opts)
if err != nil {
Expand All @@ -171,12 +174,12 @@ func main() {

// Initialize machine actuator.
machineActuator := machine.NewActuator(machine.ActuatorParams{
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
EventRecorder: mgr.GetEventRecorderFor("vspherecontroller"),
TaskIDCache: taskIDCache,
StaticIPFeatureGateEnabled: staticIPFeatureGateEnabled,
OpenshiftConfigNamespace: vsphere.OpenshiftConfigNamespace,
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
EventRecorder: mgr.GetEventRecorderFor("vspherecontroller"),
TaskIDCache: taskIDCache,
FeatureGates: defaultMutableGate,
OpenshiftConfigNamespace: vsphere.OpenshiftConfigNamespace,
})

if err := configv1.Install(mgr.GetScheme()); err != nil {
Expand Down
86 changes: 44 additions & 42 deletions pkg/controller/vsphere/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"time"

"k8s.io/component-base/featuregate"

machinev1 "github.com/openshift/api/machine/v1beta1"
machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine"
corev1 "k8s.io/api/core/v1"
Expand All @@ -27,33 +29,33 @@ const (

// Actuator is responsible for performing machine reconciliation.
type Actuator struct {
client runtimeclient.Client
apiReader runtimeclient.Reader
eventRecorder record.EventRecorder
TaskIDCache map[string]string
StaticIPFeatureGateEnabled bool
openshiftConfigNamespace string
client runtimeclient.Client
apiReader runtimeclient.Reader
eventRecorder record.EventRecorder
TaskIDCache map[string]string
FeatureGates featuregate.MutableFeatureGate
openshiftConfigNamespace string
}

// ActuatorParams holds parameter information for Actuator.
type ActuatorParams struct {
Client runtimeclient.Client
APIReader runtimeclient.Reader
EventRecorder record.EventRecorder
TaskIDCache map[string]string
StaticIPFeatureGateEnabled bool
OpenshiftConfigNamespace string
Client runtimeclient.Client
APIReader runtimeclient.Reader
EventRecorder record.EventRecorder
TaskIDCache map[string]string
FeatureGates featuregate.MutableFeatureGate
OpenshiftConfigNamespace string
}

// NewActuator returns an actuator.
func NewActuator(params ActuatorParams) *Actuator {
return &Actuator{
client: params.Client,
apiReader: params.APIReader,
eventRecorder: params.EventRecorder,
TaskIDCache: params.TaskIDCache,
StaticIPFeatureGateEnabled: params.StaticIPFeatureGateEnabled,
openshiftConfigNamespace: params.OpenshiftConfigNamespace,
client: params.Client,
apiReader: params.APIReader,
eventRecorder: params.EventRecorder,
TaskIDCache: params.TaskIDCache,
FeatureGates: params.FeatureGates,
openshiftConfigNamespace: params.OpenshiftConfigNamespace,
}
}

Expand All @@ -72,12 +74,12 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error
klog.Infof("%s: actuator creating machine", machine.GetName())

scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
featureGates: a.FeatureGates,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
})
if err != nil {
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
Expand Down Expand Up @@ -116,12 +118,12 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error
func (a *Actuator) Exists(ctx context.Context, machine *machinev1.Machine) (bool, error) {
klog.Infof("%s: actuator checking if machine exists", machine.GetName())
scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
featureGates: a.FeatureGates,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
})
if err != nil {
return false, fmt.Errorf(scopeFailFmt, machine.GetName(), err)
Expand All @@ -135,12 +137,12 @@ func (a *Actuator) Update(ctx context.Context, machine *machinev1.Machine) error
delete(a.TaskIDCache, machine.Name)

scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
featureGates: a.FeatureGates,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
})
if err != nil {
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
Expand Down Expand Up @@ -177,12 +179,12 @@ func (a *Actuator) Delete(ctx context.Context, machine *machinev1.Machine) error
delete(a.TaskIDCache, machine.Name)

scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
StaticIPFeatureGateEnabled: a.StaticIPFeatureGateEnabled,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
featureGates: a.FeatureGates,
openshiftConfigNameSpace: a.openshiftConfigNamespace,
})
if err != nil {
fmtErr := fmt.Errorf(scopeFailFmt, machine.GetName(), err)
Expand Down
42 changes: 22 additions & 20 deletions pkg/controller/vsphere/machine_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"

"k8s.io/component-base/featuregate"

machinev1 "github.com/openshift/api/machine/v1beta1"
machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine"
"github.com/openshift/machine-api-operator/pkg/controller/vsphere/session"
Expand All @@ -23,11 +25,11 @@ const (
// machineScopeParams defines the input parameters used to create a new MachineScope.
type machineScopeParams struct {
context.Context
client runtimeclient.Client
apiReader runtimeclient.Reader
machine *machinev1.Machine
StaticIPFeatureGateEnabled bool
openshiftConfigNameSpace string
client runtimeclient.Client
apiReader runtimeclient.Reader
machine *machinev1.Machine
featureGates featuregate.MutableFeatureGate
openshiftConfigNameSpace string
}

// machineScope defines a scope defined around a machine and its cluster.
Expand All @@ -42,11 +44,11 @@ type machineScope struct {
// vSphere cloud-provider config
vSphereConfig *vsphere.Config
// machine resource
machine *machinev1.Machine
providerSpec *machinev1.VSphereMachineProviderSpec
providerStatus *machinev1.VSphereMachineProviderStatus
machineToBePatched runtimeclient.Patch
staticIPFeatureGateEnabled bool
machine *machinev1.Machine
providerSpec *machinev1.VSphereMachineProviderSpec
providerStatus *machinev1.VSphereMachineProviderStatus
machineToBePatched runtimeclient.Patch
featureGates featuregate.MutableFeatureGate
}

// newMachineScope creates a new machineScope from the supplied parameters.
Expand Down Expand Up @@ -88,16 +90,16 @@ func newMachineScope(params machineScopeParams) (*machineScope, error) {
}

return &machineScope{
Context: params.Context,
client: params.client,
apiReader: params.apiReader,
session: authSession,
machine: params.machine,
providerSpec: providerSpec,
providerStatus: providerStatus,
vSphereConfig: vSphereConfig,
staticIPFeatureGateEnabled: params.StaticIPFeatureGateEnabled,
machineToBePatched: runtimeclient.MergeFrom(params.machine.DeepCopy()),
Context: params.Context,
client: params.client,
apiReader: params.apiReader,
session: authSession,
machine: params.machine,
providerSpec: providerSpec,
providerStatus: providerStatus,
vSphereConfig: vSphereConfig,
featureGates: params.featureGates,
machineToBePatched: runtimeclient.MergeFrom(params.machine.DeepCopy()),
}, nil
}

Expand Down
Loading

0 comments on commit f1a2ff8

Please sign in to comment.