Skip to content

Commit

Permalink
Changes to support vm-host group and api bump
Browse files Browse the repository at this point in the history
- Modified events.NewLoggingEventRecorder adding clock.RealClock{} param
- Add checks for failureDomain hostgroup vmgroup fields
- Add checks for machine workspace vmgroup fields
  • Loading branch information
jcpowermac committed Dec 12, 2024
1 parent 82369ad commit c354006
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cmd/control-plane-machine-set-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/spf13/pflag"
"k8s.io/utils/clock"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand Down Expand Up @@ -164,7 +165,7 @@ func main() { //nolint:funlen,cyclop
desiredVersion, missingVersion,
configInformers.Config().V1().ClusterVersions(),
configInformers.Config().V1().FeatureGates(),
events.NewLoggingEventRecorder("controlplanemachineset"),
events.NewLoggingEventRecorder("controlplanemachineset", clock.RealClock{}),
)
go featureGateAccessor.Run(context.Background())
go configInformers.Start(context.Background().Done())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (

"github.com/go-logr/logr"
"github.com/go-test/deep"
"k8s.io/apimachinery/pkg/runtime"

configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
)

// VSphereProviderConfig holds the provider spec of a VSphere Machine.
Expand Down Expand Up @@ -81,6 +82,14 @@ func (v VSphereProviderConfig) getWorkspaceFromFailureDomain(failureDomain *conf
workspace.Folder = fmt.Sprintf("/%s/vm/%s", workspace.Datacenter, v.infrastructure.Status.InfrastructureName)
}

if failureDomain.ZoneAffinity != nil {
if failureDomain.ZoneAffinity.HostGroup != nil {
if len(failureDomain.ZoneAffinity.HostGroup.VMGroup) > 0 {
workspace.VMGroup = failureDomain.ZoneAffinity.HostGroup.VMGroup
}
}
}

return workspace
}

Expand Down Expand Up @@ -172,9 +181,20 @@ func (v VSphereProviderConfig) ExtractFailureDomain() machinev1.VSphereFailureDo

for _, failureDomain := range failureDomains {
topology := failureDomain.Topology
vmGroup := ""

if failureDomain.ZoneAffinity != nil {
if failureDomain.ZoneAffinity.HostGroup != nil {
if failureDomain.ZoneAffinity.HostGroup.VMGroup != "" {
vmGroup = failureDomain.ZoneAffinity.HostGroup.VMGroup
}
}
}

if workspace.Datacenter == topology.Datacenter &&
workspace.Datastore == topology.Datastore &&
workspace.Server == failureDomain.Server &&
workspace.VMGroup == vmGroup &&
path.Clean(workspace.ResourcePool) == path.Clean(topology.ResourcePool) {
return machinev1.VSphereFailureDomain{
Name: failureDomain.Name,
Expand Down
7 changes: 5 additions & 2 deletions pkg/util/feature_gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
"os"
"time"

"k8s.io/utils/clock"

configv1client "github.com/openshift/client-go/config/clientset/versioned"
configinformers "github.com/openshift/client-go/config/informers/externalversions"

"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
"github.com/openshift/library-go/pkg/operator/events"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

const (
Expand Down Expand Up @@ -68,7 +71,7 @@ func SetupFeatureGateAccessor(mgr manager.Manager) (featuregates.FeatureGateAcce
desiredVersion, missingVersion,
configInformers.Config().V1().ClusterVersions(),
configInformers.Config().V1().FeatureGates(),
events.NewLoggingEventRecorder("controlplanemachineset"),
events.NewLoggingEventRecorder("controlplanemachineset", clock.RealClock{}),
)
go featureGateAccessor.Run(context.Background())
go configInformers.Start(context.Background().Done())
Expand Down
13 changes: 7 additions & 6 deletions pkg/webhooks/controlplanemachineset/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ import (
"strings"

"github.com/go-logr/logr"
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/machineproviders/providers/openshift/machine/v1beta1/failuredomain"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/machineproviders/providers/openshift/machine/v1beta1/providerconfig"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -39,6 +33,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/machineproviders/providers/openshift/machine/v1beta1/failuredomain"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/machineproviders/providers/openshift/machine/v1beta1/providerconfig"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/util"
)

const (
Expand Down
19 changes: 10 additions & 9 deletions pkg/webhooks/controlplanemachineset/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import (
. "github.com/onsi/gomega"
"go.uber.org/zap/zapcore"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
machinev1alpha1 "github.com/openshift/api/machine/v1alpha1"
Expand All @@ -34,15 +44,6 @@ import (
corev1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/core/v1"
machinev1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/machine/v1"
machinev1beta1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/machine/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// stringPtr returns a pointer to the string value.
Expand Down

0 comments on commit c354006

Please sign in to comment.