Skip to content

⚠️ Remove KubeadmConfig UseExperimentalRetryJoin #12234

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
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ linters:
# should be removed as the referenced deprecated item is removed from the project.
- linters:
- staticcheck
text: 'SA1019: (bootstrapv1.ClusterStatus|KubeadmConfigSpec.UseExperimentalRetryJoin|scope.Config.Spec.UseExperimentalRetryJoin|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|dockerMachine.Spec.Backend.Docker.Bootstrapped|dockerMachine.Spec.Bootstrapped|devMachine.Spec.Backend.Docker.Bootstrapped|c.TopologyPlan|clusterv1.ClusterClassVariableMetadata|clusterv1beta1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition).Metadata) is deprecated'
text: 'SA1019: (bootstrapv1.ClusterStatus|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|dockerMachine.Spec.Backend.Docker.Bootstrapped|dockerMachine.Spec.Bootstrapped|devMachine.Spec.Backend.Docker.Bootstrapped|c.TopologyPlan|clusterv1.ClusterClassVariableMetadata|clusterv1beta1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition).Metadata) is deprecated'
# Deprecations for MD revision management
- linters:
- staticcheck
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/kubeadm/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func Convert_v1beta2_KubeadmConfigStatus_To_v1beta1_KubeadmConfigStatus(in *boot
return nil
}

func Convert_v1beta1_KubeadmConfigSpec_To_v1beta2_KubeadmConfigSpec(in *KubeadmConfigSpec, out *bootstrapv1.KubeadmConfigSpec, s apimachineryconversion.Scope) error {
// NOTE: v1beta2 KubeadmConfigSpec does not have UseExperimentalRetryJoin anymore, so it's fine to just lose this field.
return autoConvert_v1beta1_KubeadmConfigSpec_To_v1beta2_KubeadmConfigSpec(in, out, s)
}

func Convert_v1beta1_KubeadmConfigStatus_To_v1beta2_KubeadmConfigStatus(in *KubeadmConfigStatus, out *bootstrapv1.KubeadmConfigStatus, s apimachineryconversion.Scope) error {
if err := autoConvert_v1beta1_KubeadmConfigStatus_To_v1beta2_KubeadmConfigStatus(in, out, s); err != nil {
return err
Expand Down
19 changes: 17 additions & 2 deletions bootstrap/kubeadm/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ func TestFuzzyConversion(t *testing.T) {
FuzzerFuncs: []fuzzer.FuzzerFuncs{KubeadmConfigFuzzFuncs},
}))
t.Run("for KubeadmConfigTemplate", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Hub: &bootstrapv1.KubeadmConfigTemplate{},
Spoke: &KubeadmConfigTemplate{},
Hub: &bootstrapv1.KubeadmConfigTemplate{},
Spoke: &KubeadmConfigTemplate{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{KubeadmConfigTemplateFuzzFuncs},
}))
}

func KubeadmConfigFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
hubKubeadmConfigStatus,
spokeKubeadmConfigSpec,
spokeKubeadmConfigStatus,
}
}
Expand All @@ -69,6 +71,13 @@ func hubKubeadmConfigStatus(in *bootstrapv1.KubeadmConfigStatus, c fuzz.Continue
}
}

func spokeKubeadmConfigSpec(in *KubeadmConfigSpec, c fuzz.Continue) {
c.FuzzNoCustom(in)

// Drop UseExperimentalRetryJoin as we intentionally don't preserve it.
in.UseExperimentalRetryJoin = false
}

func spokeKubeadmConfigStatus(in *KubeadmConfigStatus, c fuzz.Continue) {
c.FuzzNoCustom(in)
// Drop empty structs with only omit empty fields.
Expand All @@ -78,3 +87,9 @@ func spokeKubeadmConfigStatus(in *KubeadmConfigStatus, c fuzz.Continue) {
}
}
}

func KubeadmConfigTemplateFuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
spokeKubeadmConfigSpec,
}
}
18 changes: 6 additions & 12 deletions bootstrap/kubeadm/api/v1beta1/zz_generated.conversion.go

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

26 changes: 0 additions & 26 deletions bootstrap/kubeadm/api/v1beta2/kubeadmconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,6 @@ type KubeadmConfigSpec struct {
// +optional
Verbosity *int32 `json:"verbosity,omitempty"`

// useExperimentalRetryJoin replaces a basic kubeadm command with a shell
// script with retries for joins.
//
// This is meant to be an experimental temporary workaround on some environments
// where joins fail due to timing (and other issues). The long term goal is to add retries to
// kubeadm proper and use that functionality.
//
// This will add about 40KB to userdata
//
// For more information, refer to https://github.com/kubernetes-sigs/cluster-api/pull/2763#discussion_r397306055.
// +optional
//
// Deprecated: This experimental fix is no longer needed and this field will be removed in a future release.
// When removing also remove from staticcheck exclude-rules for SA1019 in golangci.yml
UseExperimentalRetryJoin bool `json:"useExperimentalRetryJoin,omitempty"`

// ignition contains Ignition specific configuration.
// +optional
Ignition *IgnitionSpec `json:"ignition,omitempty"`
Expand Down Expand Up @@ -347,16 +331,6 @@ func (c *KubeadmConfigSpec) validateIgnition(pathPrefix *field.Path) field.Error
}
}

if c.UseExperimentalRetryJoin {
allErrs = append(
allErrs,
field.Forbidden(
pathPrefix.Child("useExperimentalRetryJoin"),
cannotUseWithIgnition,
),
)
}

for i, file := range c.Files {
if file.Encoding == Gzip || file.Encoding == GzipBase64 {
allErrs = append(
Expand Down

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

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

84 changes: 18 additions & 66 deletions bootstrap/kubeadm/internal/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,49 @@ package cloudinit

import (
"bytes"
_ "embed"
"fmt"
"text/template"

"github.com/blang/semver/v4"
"github.com/pkg/errors"

bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta2"
"sigs.k8s.io/cluster-api/util/version"
)

const (
standardJoinCommand = "kubeadm join --config /run/kubeadm/kubeadm-join-config.yaml %s"
// sentinelFileCommand writes a file to /run/cluster-api to signal successful Kubernetes bootstrapping in a way that
// works both for Linux and Windows OS.
sentinelFileCommand = "echo success > /run/cluster-api/bootstrap-success.complete"
retriableJoinScriptName = "/usr/local/bin/kubeadm-bootstrap-script"
retriableJoinScriptOwner = "root"
retriableJoinScriptPermissions = "0755"
cloudConfigHeader = `## template: jinja
sentinelFileCommand = "echo success > /run/cluster-api/bootstrap-success.complete"
cloudConfigHeader = `## template: jinja
#cloud-config
`
)

// BaseUserData is shared across all the various types of files written to disk.
type BaseUserData struct {
Header string
BootCommands []string
PreKubeadmCommands []string
PostKubeadmCommands []string
AdditionalFiles []bootstrapv1.File
WriteFiles []bootstrapv1.File
Users []bootstrapv1.User
NTP *bootstrapv1.NTP
DiskSetup *bootstrapv1.DiskSetup
Mounts []bootstrapv1.MountPoints
ControlPlane bool
UseExperimentalRetry bool
KubeadmCommand string
KubeadmVerbosity string
SentinelFileCommand string
KubernetesVersion semver.Version
Header string
BootCommands []string
PreKubeadmCommands []string
PostKubeadmCommands []string
AdditionalFiles []bootstrapv1.File
WriteFiles []bootstrapv1.File
Users []bootstrapv1.User
NTP *bootstrapv1.NTP
DiskSetup *bootstrapv1.DiskSetup
Mounts []bootstrapv1.MountPoints
ControlPlane bool
KubeadmCommand string
KubeadmVerbosity string
SentinelFileCommand string
KubernetesVersion semver.Version
}

func (input *BaseUserData) prepare() error {
func (input *BaseUserData) prepare() {
input.Header = cloudConfigHeader
input.WriteFiles = append(input.WriteFiles, input.AdditionalFiles...)
input.KubeadmCommand = fmt.Sprintf(standardJoinCommand, input.KubeadmVerbosity)
if input.UseExperimentalRetry {
input.KubeadmCommand = retriableJoinScriptName
joinScriptFile, err := generateBootstrapScript(input, input.KubernetesVersion)
if err != nil {
return errors.Wrap(err, "failed to generate user data for machine joining control plane")
}
input.WriteFiles = append(input.WriteFiles, *joinScriptFile)
}
input.SentinelFileCommand = sentinelFileCommand
return nil
}

func generate(kind string, tpl string, data interface{}) ([]byte, error) {
Expand Down Expand Up @@ -124,36 +109,3 @@ func generate(kind string, tpl string, data interface{}) ([]byte, error) {

return out.Bytes(), nil
}

var (
//go:embed kubeadm-bootstrap-script-pre-k8s-1-31.sh
kubeadmBootstrapScriptPre1_31 string
//go:embed kubeadm-bootstrap-script.sh
kubeadmBootstrapScript string

// kubernetesVersion1_31 is the version where kubeadm removed the update-status phase
// and introduced new phases with the ControlPlaneKubeletLocalMode feature gate.
kubernetesVersion1_31 = semver.MustParse("1.31.0")
)

func generateBootstrapScript(input interface{}, parsedversion semver.Version) (*bootstrapv1.File, error) {
bootstrapScript := kubeadmBootstrapScript
if useKubeadmBootstrapScriptPre1_31(parsedversion) {
bootstrapScript = kubeadmBootstrapScriptPre1_31
}

joinScript, err := generate("JoinScript", bootstrapScript, input)
if err != nil {
return nil, errors.Wrap(err, "failed to bootstrap script for machine joins")
}
return &bootstrapv1.File{
Path: retriableJoinScriptName,
Owner: retriableJoinScriptOwner,
Permissions: retriableJoinScriptPermissions,
Content: string(joinScript),
}, nil
}

func useKubeadmBootstrapScriptPre1_31(parsedversion semver.Version) bool {
return version.Compare(parsedversion, kubernetesVersion1_31, version.WithoutPreReleases()) < 0
}
Loading
Loading