Skip to content

Support External Cloud Provider #1898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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 pkg/cloudprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8c.io/machine-controller/pkg/cloudprovider/provider/digitalocean"
"k8c.io/machine-controller/pkg/cloudprovider/provider/edge"
"k8c.io/machine-controller/pkg/cloudprovider/provider/equinixmetal"
"k8c.io/machine-controller/pkg/cloudprovider/provider/external"
"k8c.io/machine-controller/pkg/cloudprovider/provider/fake"
"k8c.io/machine-controller/pkg/cloudprovider/provider/gce"
"k8c.io/machine-controller/pkg/cloudprovider/provider/hetzner"
Expand Down Expand Up @@ -111,6 +112,9 @@ var (
providerconfigtypes.CloudProviderVMwareCloudDirector: func(cvr *providerconfig.ConfigVarResolver) cloudprovidertypes.Provider {
return vcd.New(cvr)
},
providerconfigtypes.CloudProviderExternal: func(cvr *providerconfig.ConfigVarResolver) cloudprovidertypes.Provider {
return external.New(cvr)
},
}

// communityProviders holds a map of cloud providers that have been implemented by community members and
Expand Down
95 changes: 95 additions & 0 deletions pkg/cloudprovider/provider/external/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
Copyright 2025 The Machine Controller Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package external

import (
"context"
"go.uber.org/zap"

clusterv1alpha1 "k8c.io/machine-controller/pkg/apis/cluster/v1alpha1"
"k8c.io/machine-controller/pkg/cloudprovider/instance"
cloudprovidertypes "k8c.io/machine-controller/pkg/cloudprovider/types"
"k8c.io/machine-controller/pkg/providerconfig"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)

type provider struct{}

type CloudProviderSpec struct {
}

type CloudProviderInstance struct{}

func (f CloudProviderInstance) Name() string {
return ""
}

func (f CloudProviderInstance) ID() string {
return ""
}

func (f CloudProviderInstance) ProviderID() string {
return ""
}

func (f CloudProviderInstance) Addresses() map[string]corev1.NodeAddressType {
return nil
}

func (f CloudProviderInstance) Status() instance.Status {
return instance.StatusUnknown
}

// New returns an external cloud provider.
func New(_ *providerconfig.ConfigVarResolver) cloudprovidertypes.Provider {
return &provider{}
}

func (p *provider) AddDefaults(_ *zap.SugaredLogger, spec clusterv1alpha1.MachineSpec) (clusterv1alpha1.MachineSpec, error) {
return spec, nil
}

// Validate returns success or failure based according to its ExternalCloudProviderSpec.
func (p *provider) Validate(_ context.Context, _ *zap.SugaredLogger, _ clusterv1alpha1.MachineSpec) error {
return nil
}

func (p *provider) Get(_ context.Context, _ *zap.SugaredLogger, _ *clusterv1alpha1.Machine, _ *cloudprovidertypes.ProviderData) (instance.Instance, error) {
return CloudProviderInstance{}, nil
}

// Create creates a cloud instance according to the given machine.
func (p *provider) Create(_ context.Context, _ *zap.SugaredLogger, _ *clusterv1alpha1.Machine, _ *cloudprovidertypes.ProviderData, _ string) (instance.Instance, error) {
return CloudProviderInstance{}, nil
}

func (p *provider) Cleanup(_ context.Context, _ *zap.SugaredLogger, _ *clusterv1alpha1.Machine, _ *cloudprovidertypes.ProviderData) (bool, error) {
return true, nil
}

func (p *provider) MigrateUID(_ context.Context, _ *zap.SugaredLogger, _ *clusterv1alpha1.Machine, _ types.UID) error {
return nil
}

func (p *provider) MachineMetricsLabels(_ *clusterv1alpha1.Machine) (map[string]string, error) {
return map[string]string{}, nil
}

func (p *provider) SetMetricsForMachines(_ clusterv1alpha1.MachineList) error {
return nil
}
10 changes: 8 additions & 2 deletions pkg/controller/machine/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,14 @@ func (r *Reconciler) deleteCloudProviderInstance(ctx context.Context, log *zap.S

return nil, r.updateMachine(machine, func(m *clusterv1alpha1.Machine) {
finalizers := sets.NewString(m.Finalizers...)
finalizers.Delete(FinalizerDeleteInstance)
m.Finalizers = finalizers.List()
// If a machine deployment belongs to an external cloud provider, the 'machine-delete-finalizer' must be manually
// removed by an administrator or an external service. This is because the machine controller lacks access to cloud
// instances and cannot ensure their deletion. If the external service fails to delete the instance, it may result
// in orphaned resources or nodes without a machine reference.
if machineConfig.CloudProvider != providerconfigtypes.CloudProviderExternal {
finalizers.Delete(FinalizerDeleteInstance)
m.Finalizers = finalizers.List()
}
})
}

Expand Down
1 change: 1 addition & 0 deletions pkg/providerconfig/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var (
CloudProviderBaremetal,
CloudProviderVultr,
CloudProviderOpenNebula,
CloudProviderExternal,
}
)

Expand Down