Skip to content

Commit

Permalink
Initial Kubevirt provider implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Mudrinić <[email protected]>
  • Loading branch information
xmudrii committed Oct 25, 2024
1 parent a5492d8 commit 27fa07f
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/kubeone/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ func (p CloudProviderSpec) CloudProviderName() string {
return "gce"
case p.Hetzner != nil:
return "hetzner"
case p.Kubevirt != nil:
return "kubevirt"
case p.Nutanix != nil:
return "nutanix"
case p.Openstack != nil:
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/kubeone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ type CloudProviderSpec struct {
// Hetzner
Hetzner *HetznerSpec `json:"hetzner,omitempty"`

// Kubevirt
Kubevirt *KubevirtSpec `json:"kubevirt,omitempty"`

// Nutanix
Nutanix *NutanixSpec `json:"nutanix,omitempty"`

Expand Down Expand Up @@ -435,6 +438,9 @@ type HetznerSpec struct {
NetworkID string `json:"networkID,omitempty"`
}

// KubevirtSpec defines the Kubevirt provider
type KubevirtSpec struct{}

// NutanixSpec defines the Nutanix provider
type NutanixSpec struct{}

Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/kubeone/v1beta2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ func SetDefaults_CloudProvider(obj *KubeOneCluster) {
// if kubernetes version is 1.29+
// and cloud provider is configured
if gteKube129Condition.Check(actualVer) && obj.CloudProvider.None == nil {
// and cloud provider is NOT VMwareCloudDirector, to prevent kubelet --cloud-provider=external situation where
// there will be no CCM (VMwareCloudDirector have no CCM) to initialize the Node
if obj.CloudProvider.VMwareCloudDirector == nil {
// and cloud provider is NOT Kubevirt and NOT VMwareCloudDirector,
// to prevent kubelet --cloud-provider=external situation where
// there will be no CCM to initialize the Node
if obj.CloudProvider.Kubevirt == nil && obj.CloudProvider.VMwareCloudDirector == nil {
obj.CloudProvider.External = true
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kubeone/v1beta2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func SetCloudProvider(cp *CloudProviderSpec, name string) error {
cp.GCE = &GCESpec{}
case "hetzner":
cp.Hetzner = &HetznerSpec{}
case "kubevirt":
cp.Kubevirt = &KubevirtSpec{}
case "nutanix":
cp.Nutanix = &NutanixSpec{}
case "openstack":
Expand Down Expand Up @@ -69,6 +71,8 @@ func (cps *CloudProviderSpec) Name() string {
return "gce"
case cps.Hetzner != nil:
return "hetzner"
case cps.Kubevirt != nil:
return "kubevirt"
case cps.Nutanix != nil:
return "nutanix"
case cps.Openstack != nil:
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/kubeone/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ type CloudProviderSpec struct {
// Hetzner
Hetzner *HetznerSpec `json:"hetzner,omitempty"`

// Kubevirt
Kubevirt *KubevirtSpec `json:"kubevirt,omitempty"`

// Nutanix
Nutanix *NutanixSpec `json:"nutanix,omitempty"`

Expand Down Expand Up @@ -440,6 +443,9 @@ type HetznerSpec struct {
NetworkID string `json:"networkID,omitempty"`
}

// KubevirtSpec defines the Kubevirt provider
type KubevirtSpec struct{}

// NutanixSpec defines the Nutanix provider
type NutanixSpec struct{}

Expand Down
30 changes: 30 additions & 0 deletions pkg/apis/kubeone/v1beta2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/apis/kubeone/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pkg/apis/kubeone/v1beta3/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ func SetDefaults_CloudProvider(obj *KubeOneCluster) {
// if kubernetes version is 1.29+
// and cloud provider is configured
if gteKube129Condition.Check(actualVer) && obj.CloudProvider.None == nil {
// and cloud provider is NOT VMwareCloudDirector, to prevent kubelet --cloud-provider=external situation where
// there will be no CCM (VMwareCloudDirector have no CCM) to initialize the Node
if obj.CloudProvider.VMwareCloudDirector == nil {
// and cloud provider is NOT VMwareCloudDirector and NOT Kubevirt,
// to prevent kubelet --cloud-provider=external situation where
// there will be no CCM to initialize the Node
if obj.CloudProvider.Kubevirt == nil && obj.CloudProvider.VMwareCloudDirector == nil {
obj.CloudProvider.External = true
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kubeone/v1beta3/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func SetCloudProvider(cp *CloudProviderSpec, name string) error {
cp.GCE = &GCESpec{}
case "hetzner":
cp.Hetzner = &HetznerSpec{}
case "kubevirt":
cp.Kubevirt = &KubevirtSpec{}
case "nutanix":
cp.Nutanix = &NutanixSpec{}
case "openstack":
Expand Down Expand Up @@ -69,6 +71,8 @@ func (cps *CloudProviderSpec) Name() string {
return "gce"
case cps.Hetzner != nil:
return "hetzner"
case cps.Kubevirt != nil:
return "kubevirt"
case cps.Nutanix != nil:
return "nutanix"
case cps.Openstack != nil:
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/kubeone/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ type CloudProviderSpec struct {
// Hetzner
Hetzner *HetznerSpec `json:"hetzner,omitempty"`

// Kubevirt
Kubevirt *KubevirtSpec `json:"kubevirt,omitempty"`

// Nutanix
Nutanix *NutanixSpec `json:"nutanix,omitempty"`

Expand Down Expand Up @@ -432,6 +435,9 @@ type HetznerSpec struct {
NetworkID string `json:"networkID,omitempty"`
}

// KubevirtSpec defines the Kubevirt provider
type KubevirtSpec struct{}

// NutanixSpec defines the Nutanix provider
type NutanixSpec struct{}

Expand Down
30 changes: 30 additions & 0 deletions pkg/apis/kubeone/v1beta3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/apis/kubeone/v1beta3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/apis/kubeone/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ func ValidateCloudProviderSpec(providerSpec kubeoneapi.CloudProviderSpec, networ
}
providerFound = true
}
if providerSpec.Kubevirt != nil {
if providerFound {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("kubevirt"), "only one provider can be used at the same time"))
}
providerFound = true
if providerSpec.External {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("external"), "external cloud provider is not supported for Kubevirt clusters"))
}
}
if providerSpec.Nutanix != nil {
if providerFound {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("nutanix"), "only one provider can be used at the same time"))
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/kubeone/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ func TestValidateCloudProviderSpec(t *testing.T) {
},
expectedError: false,
},
{
name: "valid Kubevirt provider config",
providerConfig: kubeoneapi.CloudProviderSpec{
Kubevirt: &kubeoneapi.KubevirtSpec{},
},
expectedError: false,
},
{
name: "valid Nutanix provider config",
providerConfig: kubeoneapi.CloudProviderSpec{
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/kubeone/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 27fa07f

Please sign in to comment.