Skip to content

Commit

Permalink
Merge pull request kubernetes#123595 from neolit123/1.30-add-timeouts…
Browse files Browse the repository at this point in the history
…-upgradeconfig

kubeadm: add timeouts to v1beta4.UpgradeConfiguration
  • Loading branch information
k8s-ci-robot committed Mar 4, 2024
2 parents d440ab1 + 99313be commit 9d39ce0
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 48 deletions.
1 change: 1 addition & 0 deletions cmd/kubeadm/app/apis/kubeadm/fuzzer/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ func fuzzUpgradeConfiguration(obj *kubeadm.UpgradeConfiguration, c fuzz.Continue
obj.Apply.EtcdUpgrade = ptr.To(true)
obj.Apply.CertificateRenewal = ptr.To(false)
obj.Node.CertificateRenewal = ptr.To(false)
kubeadm.SetDefaultTimeouts(&obj.Timeouts)
}
1 change: 1 addition & 0 deletions cmd/kubeadm/app/apis/kubeadm/timeoututils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func SetDefaultTimeouts(t **Timeouts) {
EtcdAPICall: &metav1.Duration{Duration: constants.EtcdAPICallTimeout},
TLSBootstrap: &metav1.Duration{Duration: constants.TLSBootstrapTimeout},
Discovery: &metav1.Duration{Duration: constants.DiscoveryTimeout},
UpgradeManifests: &metav1.Duration{Duration: constants.UpgradeManifestsTimeout},
}
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ type UpgradeConfiguration struct {

// Plan holds a list of options that are specific to the "kubeadm upgrade plan" command.
Plan UpgradePlanConfiguration

// Timeouts holds various timeouts that apply to kubeadm commands.
Timeouts *Timeouts
}

const (
Expand Down Expand Up @@ -724,4 +727,7 @@ type Timeouts struct {
// Discovery is the amount of time to wait for kubeadm to validate the API server identity
// for a joining node.
Discovery *metav1.Duration

// UpgradeManifests is the timeout for upgradring static Pod manifests
UpgradeManifests *metav1.Duration
}
9 changes: 9 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1beta4/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ func SetDefaults_Timeouts(obj *Timeouts) {
Duration: constants.DiscoveryTimeout,
}
}
if obj.UpgradeManifests == nil {
obj.UpgradeManifests = &metav1.Duration{
Duration: constants.UpgradeManifestsTimeout,
}
}
}

// SetDefaults_UpgradeConfiguration assigns default values for the UpgradeConfiguration
Expand All @@ -274,4 +279,8 @@ func SetDefaults_UpgradeConfiguration(obj *UpgradeConfiguration) {
if obj.Apply.CertificateRenewal == nil {
obj.Apply.CertificateRenewal = ptr.To(true)
}
if obj.Timeouts == nil {
obj.Timeouts = &Timeouts{}
}
SetDefaults_Timeouts(obj.Timeouts)
}
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/apis/kubeadm/v1beta4/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ limitations under the License.
// - Add `ClusterConfiguration.DNS.Disabled` and `ClusterConfiguration.Proxy.Disabled` that can be used to disable
// the CoreDNS and kube-proxy addons during cluster initialization. Skipping the related addons phases,
// during cluster creation will set the same fields to `false`.
// - Add a `Timeouts` structure to `InitConfiguration`, `JoinConfiguration` and `ResetConfiguration“
// that can be used to configure various timeouts.
// - Add the `NodeRegistration.ImagePullSerial` field in 'InitConfiguration` and `JoinConfiguration`, which
// can be used to control if kubeadm pulls images serially or in parallel.
// - The UpgradeConfiguration kubeadm API is now supported in v1beta4 when passing --config to "kubeadm upgrade" subcommands.
// Usage of component configuration for kubelet and kube-proxy, InitConfiguration and ClusterConfiguration is deprecated
// and will be ignored when passing --config to upgrade subcommands.
// - Add a `Timeouts` structure to `InitConfiguration`, `JoinConfiguration`, `ResetConfiguration` and `UpgradeConfiguration`
// that can be used to configure various timeouts.
//
// Migration from old kubeadm config versions
//
Expand Down
8 changes: 8 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1beta4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ type Timeouts struct {
// Default: 5m
// +optional
Discovery *metav1.Duration `json:"discovery,omitempty"`

// UpgradeManifests is the timeout for upgradring static Pod manifests
// Default: 5m
UpgradeManifests *metav1.Duration `json:"upgradeManifests,omitempty"`
}

// UpgradeApplyConfiguration contains a list of configurable options which are specific to the "kubeadm upgrade apply" command.
Expand Down Expand Up @@ -744,4 +748,8 @@ type UpgradeConfiguration struct {
// Plan holds a list of options that are specific to the "kubeadm upgrade plan" command.
// +optional
Plan UpgradePlanConfiguration `json:"plan,omitempty"`

// Timeouts holds various timeouts that apply to kubeadm commands.
// +optional
Timeouts *Timeouts `json:"timeouts,omitempty"`
}

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

10 changes: 10 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.defaults.go

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

3 changes: 3 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,5 +765,8 @@ func ValidateUpgradeConfiguration(c *kubeadm.UpgradeConfiguration) field.ErrorLi
if c.Apply.Patches != nil {
allErrs = append(allErrs, ValidateAbsolutePath(c.Apply.Patches.Directory, field.NewPath("patches").Child("directory"))...)
}
if c.Node.Patches != nil {
allErrs = append(allErrs, ValidateAbsolutePath(c.Node.Patches.Directory, field.NewPath("patches").Child("directory"))...)
}
return allErrs
}
10 changes: 10 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion cmd/kubeadm/app/cmd/phases/upgrade/node/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func runControlPlane() func(c workflow.RunData) error {
return upgrade.DryRunStaticPodUpgrade(patchesDir, cfg)
}

waiter := apiclient.NewKubeWaiter(data.Client(), upgrade.UpgradeManifestTimeout, os.Stdout)
waiter := apiclient.NewKubeWaiter(data.Client(), data.Cfg().Timeouts.UpgradeManifests.Duration, os.Stdout)

if err := upgrade.PerformStaticPodUpgrade(client, waiter, cfg, etcdUpgrade, renewCerts, patchesDir); err != nil {
return errors.Wrap(err, "couldn't complete the static pod upgrade")
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/cmd/upgrade/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func runApply(flagSet *pflag.FlagSet, flags *applyFlags, args []string) error {
fmt.Println("[upgrade/prepull] Would pull the required images (like 'kubeadm config images pull')")
}

waiter := getWaiter(flags.dryRun, client, upgrade.UpgradeManifestTimeout)
waiter := getWaiter(flags.dryRun, client, upgradeCfg.Timeouts.UpgradeManifests.Duration)

// If the config is set by flag, just overwrite it!
etcdUpgrade, ok := cmdutil.ValueFromFlagsOrConfig(flagSet, options.EtcdUpgrade, upgradeCfg.Apply.EtcdUpgrade, &flags.etcdUpgrade).(*bool)
Expand Down Expand Up @@ -260,7 +260,7 @@ func EnforceVersionPolicies(newK8sVersionStr string, newK8sVersion *version.Vers
func PerformControlPlaneUpgrade(flags *applyFlags, client clientset.Interface, waiter apiclient.Waiter, initCfg *kubeadmapi.InitConfiguration, upgradeCfg *kubeadmapi.UpgradeConfiguration) error {
// OK, the cluster is hosted using static pods. Upgrade a static-pod hosted cluster
fmt.Printf("[upgrade/apply] Upgrading your Static Pod-hosted control plane to version %q (timeout: %v)...\n",
initCfg.KubernetesVersion, upgrade.UpgradeManifestTimeout)
initCfg.KubernetesVersion, upgradeCfg.Timeouts.UpgradeManifests.Duration)

if flags.dryRun {
return upgrade.DryRunStaticPodUpgrade(upgradeCfg.Apply.Patches.Directory, initCfg)
Expand Down
5 changes: 4 additions & 1 deletion cmd/kubeadm/app/cmd/upgrade/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
Expand All @@ -55,7 +56,9 @@ func enforceRequirements(flagSet *pflag.FlagSet, flags *applyPlanFlags, args []s
// Fetch the configuration from a file or ConfigMap and validate it
_, _ = printer.Printf("[upgrade/config] Making sure the configuration is correct:\n")

upgradeCfg, err := configutil.LoadUpgradeConfig(flags.cfgPath)
externalCfg := &v1beta4.UpgradeConfiguration{}
opt := configutil.LoadOrDefaultConfigurationOptions{}
upgradeCfg, err := configutil.LoadOrDefaultUpgradeConfiguration(flags.cfgPath, externalCfg, opt)
if err != nil {
return nil, nil, nil, nil, errors.Wrap(err, "[upgrade/upgrade config] FATAL")
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/kubeadm/app/cmd/upgrade/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/klog/v2"

kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
Expand Down Expand Up @@ -118,7 +119,9 @@ func validateManifestsPath(manifests ...string) (err error) {
type FetchInitConfigurationFunc func(client clientset.Interface, printer output.Printer, logPrefix string, newControlPlane, skipComponentConfigs bool) (*kubeadmapi.InitConfiguration, error)

func runDiff(fs *pflag.FlagSet, flags *diffFlags, args []string, fetchInitConfigurationFromCluster FetchInitConfigurationFunc) error {
upgradeCfg, err := configutil.LoadUpgradeConfig(flags.cfgPath)
externalCfg := &v1beta4.UpgradeConfiguration{}
opt := configutil.LoadOrDefaultConfigurationOptions{}
upgradeCfg, err := configutil.LoadOrDefaultUpgradeConfiguration(flags.cfgPath, externalCfg, opt)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/kubeadm/app/cmd/upgrade/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/pkg/errors"

clientset "k8s.io/client-go/kubernetes"

kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
"k8s.io/kubernetes/cmd/kubeadm/app/util/output"
Expand Down Expand Up @@ -57,7 +58,9 @@ func TestRunDiff(t *testing.T) {
testUpgradeDiffConfigContents := []byte(fmt.Sprintf(`
apiVersion: %s
kind: UpgradeConfiguration
contextLines: 4`, kubeadmapiv1.SchemeGroupVersion.String()))
diff:
contextLines: 4`, kubeadmapiv1.SchemeGroupVersion.String()))

testUpgradeDiffConfig, err := createTestRunDiffFile(testUpgradeDiffConfigContents)
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 4 additions & 1 deletion cmd/kubeadm/app/cmd/upgrade/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
clientset "k8s.io/client-go/kubernetes"

kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
phases "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/upgrade/node"
Expand Down Expand Up @@ -155,7 +156,9 @@ func newNodeData(cmd *cobra.Command, args []string, nodeOptions *nodeOptions, ou
}
}

upgradeCfg, err := configutil.LoadUpgradeConfig(nodeOptions.cfgPath)
externalCfg := &v1beta4.UpgradeConfiguration{}
opt := configutil.LoadOrDefaultConfigurationOptions{}
upgradeCfg, err := configutil.LoadOrDefaultUpgradeConfiguration(nodeOptions.cfgPath, externalCfg, opt)
if err != nil {
return nil, err
}
Expand Down
10 changes: 3 additions & 7 deletions cmd/kubeadm/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,6 @@ const (
// TLSBootstrapRetryInterval specifies how long kubeadm should wait before retrying the TLS Bootstrap check
TLSBootstrapRetryInterval = 1 * time.Second

// StaticPodMirroringTimeout specifies how much time kubeadm should wait for the static pods
// to be mirrored on the API server.
StaticPodMirroringTimeout = 30 * time.Second
// StaticPodMirroringRetryInterval specifies how often to check if static pods are mirrored at the
// API server.
StaticPodMirroringRetryInterval = 500 * time.Millisecond

// EtcdAPICallTimeout specifies how much time to wait for completion of requests against the etcd API.
EtcdAPICallTimeout = 2 * time.Minute
// EtcdAPICallRetryInterval specifies how frequently to retry requests against the etcd API.
Expand All @@ -241,6 +234,9 @@ const (
// KubeletHealthCheckTimeout specifies the default kubelet timeout
KubeletHealthCheckTimeout = 4 * time.Minute

// UpgradeManifestsTimeout specifies the default timeout for upgradring static Pod manifests
UpgradeManifestsTimeout = 5 * time.Minute

// PullImageRetry specifies how many times ContainerRuntime retries when pulling image failed
PullImageRetry = 5
// RemoveContainerRetry specifies how many times ContainerRuntime retries when removing container failed
Expand Down
7 changes: 1 addition & 6 deletions cmd/kubeadm/app/phases/upgrade/staticpods.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ import (
"k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod"
)

const (
// UpgradeManifestTimeout is timeout of upgrading the static pod manifest
UpgradeManifestTimeout = 5 * time.Minute
)

// StaticPodPathManager is responsible for tracking the directories used in the static pod upgrade transition
type StaticPodPathManager interface {
// MoveFile should move a file from oldPath to newPath
Expand Down Expand Up @@ -246,7 +241,7 @@ func upgradeComponent(component string, certsRenewMgr *renewal.Manager, waiter a
fmt.Printf("[upgrade/staticpods] Moved new manifest to %q and backed up old manifest to %q\n", currentManifestPath, backupManifestPath)

fmt.Println("[upgrade/staticpods] Waiting for the kubelet to restart the component")
fmt.Printf("[upgrade/staticpods] This might take a minute or longer depending on the component/version gap (timeout %v)\n", UpgradeManifestTimeout)
fmt.Printf("[upgrade/staticpods] This can take up to %v\n", kubeadmapi.GetActiveTimeouts().UpgradeManifests.Duration)

// Wait for the mirror Pod hash to change; otherwise we'll run into race conditions here when the kubelet hasn't had time to
// notice the removal of the Static Pod, leading to a false positive below where we check that the API endpoint is healthy
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubeadm/app/util/config/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func getNodeNameFromKubeletConfig(fileName string) (string, error) {

func getAPIEndpoint(client clientset.Interface, nodeName string, apiEndpoint *kubeadmapi.APIEndpoint) error {
return getAPIEndpointWithRetry(client, nodeName, apiEndpoint,
constants.StaticPodMirroringRetryInterval, constants.StaticPodMirroringTimeout)
constants.KubernetesAPICallRetryInterval, kubeadmapi.GetActiveTimeouts().KubernetesAPICall.Duration)
}

func getAPIEndpointWithRetry(client clientset.Interface, nodeName string, apiEndpoint *kubeadmapi.APIEndpoint,
Expand Down
8 changes: 5 additions & 3 deletions cmd/kubeadm/app/util/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,13 @@ func isKubeadmPrereleaseVersion(versionInfo *apimachineryversion.Info, k8sVersio
func prepareStaticVariables(config any) {
switch c := config.(type) {
case *kubeadmapi.InitConfiguration:
kubeadmapi.SetActiveTimeouts(c.Timeouts.DeepCopy())
kubeadmapi.SetActiveTimeouts(c.Timeouts)
case *kubeadmapi.JoinConfiguration:
kubeadmapi.SetActiveTimeouts(c.Timeouts.DeepCopy())
kubeadmapi.SetActiveTimeouts(c.Timeouts)
case *kubeadmapi.ResetConfiguration:
kubeadmapi.SetActiveTimeouts(c.Timeouts.DeepCopy())
kubeadmapi.SetActiveTimeouts(c.Timeouts)
case *kubeadmapi.UpgradeConfiguration:
kubeadmapi.SetActiveTimeouts(c.Timeouts)
}
}

Expand Down
Loading

0 comments on commit 9d39ce0

Please sign in to comment.