Skip to content
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

Cloud-config is not required for external cloud providers #353

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
21 changes: 20 additions & 1 deletion pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package cloudprovider

import (
"errors"
"fmt"

"github.com/Masterminds/semver/v3"

providerconfigtypes "github.com/kubermatic/machine-controller/pkg/providerconfig/types"
"k8c.io/operating-system-manager/pkg/cloudprovider/aws"
Expand All @@ -30,7 +33,23 @@ import (
)

// GetCloudConfig will return the cloud-config for machine
func GetCloudConfig(pconfig providerconfigtypes.Config, kubeletVersion string) (string, error) {
func GetCloudConfig(external bool, pconfig providerconfigtypes.Config, kubeletVersion string) (string, error) {
// cloud-config is not required by the kubelet for external cloud providers.
if external {
return "", nil
}

// In-tree cloud providers have been disabled starting from k8s 1.29 hence we don't need to generate cloud-config for them.
gteKube129Condition, _ := semver.NewConstraint(">= 1.29")
kubeSemVer, err := semver.NewVersion(kubeletVersion)
if err != nil {
return "", fmt.Errorf("failed to parse kubelet version: %w", err)
}

if gteKube129Condition.Check(kubeSemVer) {
return "", nil
}

cloudProvider := osmv1alpha1.CloudProvider(pconfig.CloudProvider)

switch cloudProvider {
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusterinfo/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *KubeconfigProvider) buildKubeconfigFromEndpoint(ctx context.Context) (*
return nil, errors.New("could not parse ip from ")
}

getSecurePort := func(endpointSubset corev1.EndpointSubset) *corev1.EndpointPort {
getSecurePort := func(_ corev1.EndpointSubset) *corev1.EndpointPort {
for _, p := range subset.Ports {
if p.Name == securePortName {
return &p
Expand Down
21 changes: 8 additions & 13 deletions pkg/controllers/osc/resources/operating_system_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ func GenerateOperatingSystemConfig(

networkIPFamily := providerConfig.Network.GetIPFamily()

var cloudConfig string
if providerConfig.OverwriteCloudConfig != nil {
cloudConfig = *providerConfig.OverwriteCloudConfig
} else {
cloudConfig, err = cloudprovider.GetCloudConfig(providerConfig, md.Spec.Template.Spec.Versions.Kubelet)
if err != nil {
return nil, fmt.Errorf("failed to fetch cloud-config: %w", err)
}
}

// Ensure that Kubelet version is prefixed by "v"
kubeletVersion, err := semver.NewVersion(md.Spec.Template.Spec.Versions.Kubelet)
if err != nil {
Expand Down Expand Up @@ -172,9 +162,14 @@ func GenerateOperatingSystemConfig(
return nil, err
}

if external &&
osmv1alpha1.CloudProvider(providerConfig.CloudProvider) == osmv1alpha1.CloudProviderVsphere {
cloudConfig = ""
var cloudConfig string
if providerConfig.OverwriteCloudConfig != nil {
cloudConfig = *providerConfig.OverwriteCloudConfig
} else {
cloudConfig, err = cloudprovider.GetCloudConfig(external, providerConfig, md.Spec.Template.Spec.Versions.Kubelet)
if err != nil {
return nil, fmt.Errorf("failed to fetch cloud-config: %w", err)
}
}

data := filesData{
Expand Down
6 changes: 1 addition & 5 deletions pkg/controllers/osc/testdata/osc-flatcar-aws-containerd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,7 @@ spec:
permissions: 644
- content:
inline:
data: |+
[global]
Zone="eu-central-1b"
VPC="e-123f"
SubnetID="test-subnet"
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ spec:
permissions: 644
- content:
inline:
data: |+
[global]
Zone="eu-central-1b"
VPC="e-123f"
SubnetID="test-subnet"
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ spec:
permissions: 644
- content:
inline:
data: |
{"cloud":"AZUREPUBLICCLOUD","tenantId":"","subscriptionId":"","aadClientId":"","aadClientSecret":"","resourceGroup":"","location":"","vnetName":"","subnetName":"","routeTableName":"","securityGroupName":"fake-sg","primaryAvailabilitySetName":"","vnetResourceGroup":"","useInstanceMetadata":true,"loadBalancerSku":""}
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
permissions: 600
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,7 @@ spec:
permissions: 644
- content:
inline:
data: |+
[global]
Zone="eu-central-1b"
VPC="e-123f"
SubnetID="test-subnet"
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
Expand Down
6 changes: 1 addition & 5 deletions pkg/controllers/osc/testdata/osc-ubuntu-aws-containerd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,7 @@ spec:
permissions: 644
- content:
inline:
data: |+
[global]
Zone="eu-central-1b"
VPC="e-123f"
SubnetID="test-subnet"
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,7 @@ spec:
permissions: 644
- content:
inline:
data: |+
[global]
Zone="eu-central-1b"
VPC="e-123f"
SubnetID="test-subnet"
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
Expand Down
6 changes: 1 addition & 5 deletions pkg/controllers/osc/testdata/osc-ubuntu-aws-dualstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,7 @@ spec:
permissions: 644
- content:
inline:
data: |+
[global]
Zone="eu-central-1b"
VPC="e-123f"
SubnetID="test-subnet"
data: |2+

encoding: b64
path: /etc/kubernetes/cloud-config
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pkg/controllers/osp/osp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ func parseYAMLToObject(ospByte []byte) (*v1alpha1.OperatingSystemProfile, error)
// filterDeploymentPredicate filters out all deployment events except the creation one.
func filterDeploymentPredicate() predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
CreateFunc: func(_ event.CreateEvent) bool {
return true
},
DeleteFunc: func(e event.DeleteEvent) bool {
DeleteFunc: func(_ event.DeleteEvent) bool {
return false
},
UpdateFunc: func(e event.UpdateEvent) bool {
UpdateFunc: func(_ event.UpdateEvent) bool {
return false
},
GenericFunc: func(e event.GenericEvent) bool {
GenericFunc: func(_ event.GenericEvent) bool {
return false
},
}
Expand Down