Commit Graph

3324 Commits

Author SHA1 Message Date
Rostislav M. Georgiev
930ca6ceb2 kubeadm: Refactor component config tests
Over the course of recent development of the `componentconfigs` package,
it became evident that most of the tests in this package cannot be implemented without
using a component config. As all of the currently supported component configs are
external to the kubeadm project (kubelet and kube-proxy), practically all of the tests
in this package are now dependent on external code.
This is not desirable, because other component's configs may change frequently and
without much of a notice. In particular many configs add new fields without bumping their
versions. In addition to that, some components may be deprecated in the future and many
tests may use their configs as a place holder of a component config just to test some
common functionality.
To top that, there are many tests that test the same common functionality several times
(for each different component config).

Thus a kubeadm managed replacement and a fake test environment are introduced.
The new test environment uses kubeadm's very own `ClusterConfiguration`.
ClusterConfiguration is normally not managed by the `componentconfigs` package.
It's only used, because of the following:
- It's a versioned API that is under the control of kubeadm maintainers. This enables us to test
  the componentconfigs package more thoroughly without having to have full and always up to date
  knowledge about the config of another component.
- Other components often introduce new fields in their configs without bumping up the config version.
  This, often times, requires that the PR that introduces such new fields to touch kubeadm test code.
  Doing so, requires more work on the part of developers and reviewers. When kubeadm moves out of k/k
  this would allow for more sporadic breaks in kubeadm tests as PRs that merge in k/k and introduce
  new fields won't be able to fix the tests in kubeadm.
- If we implement tests for all common functionality using the config of another component and it gets
  deprecated and/or we stop supporting it in production, we'll have to focus on a massive test refactoring
  or just continue importing this config just for test use.

Thus, to reduce maintenance costs without sacrificing test coverage, we introduce this mini-framework
and set of tests here which replace the normal component configs with a single one (`ClusterConfiguration`)
and test the component config independent logic of this package.

As a result of this, many of the older test cases are refactored and greatly simplified to reflect
on the new change as well. The old tests that are strictly tied to specific component configs
(like the defaulting tests) are left unchanged.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-07-03 20:00:45 +03:00
Kubernetes Prow Robot
af29f81af6
Merge pull request #92740 from SataQiu/deprecate-config-view-20200702
Mark 'kubeadm config view' command as deprecated
2020-07-03 05:04:02 -07:00
Kubernetes Prow Robot
046ac5100e
Merge pull request #92720 from neolit123/1.19-add-kcm-port
kubeadm: add --port=0 for kube-controller-manager and kube-scheduler
2020-07-03 05:03:25 -07:00
Kubernetes Prow Robot
a2aaae2dd5
Merge pull request #88124 from rosti/kubeadm-cc-upgrade-plan
kubeadm upgrade plan: print a component config state table
2020-07-03 05:02:47 -07:00
SataQiu
2b7af10276 mark 'kubeadm config view' command as deprecated 2020-07-03 09:40:23 +08:00
Kubernetes Prow Robot
13a4a71e99
Merge pull request #91532 from afrouzMashaykhi/log-flag-kubelet
add --logging-format flag to kubelet
2020-07-02 06:40:46 -07:00
Kubernetes Prow Robot
d71a09271c
Merge pull request #92017 from neolit123/1.19-patches
kubeadm: introduce --experimental-patches and deprecate --experimental-kustomize
2020-07-02 04:17:01 -07:00
Lubomir I. Ivanov
f66513d98a kubeadm: add --port=0 for kube-controller-manager and kube-scheduler
Kubeadm setup of kube-controller-manager and kube-scheduler is
lacking the --port=0 option which caused the component to enable
the insecure port by default and serve insecurely on the default
node interface.

Add --port=0 by default to both components. Users are still allowed
the explicitly set the flag (via extraArgs), which allows them
to override this default kubeadm behavior and enable the insecure port.

NOTE: the flag is deprecated and should be removed from kubeadm manifests
once it's removed from core.
2020-07-01 22:23:21 +03:00
amash
3ab25f1876 add LoggingConfiguration struct to component-base/config 2020-07-01 20:07:01 +04:30
amash
ac8d2e8978 add loggingConfig struct to kubelet config 2020-07-01 20:07:01 +04:30
Kubernetes Prow Robot
4c523b1981
Merge pull request #92131 from SataQiu/fix-etcd-opt-20200615
kubeadm: increase robustness for kubeadm etcd operations
2020-07-01 00:06:21 -07:00
Rostislav M. Georgiev
b51f2c1d1c kubeadm: Remove kubeadm config upload
`kubeadm config upload` is a GA command that has been deprecated and scheduled
for removal since Kubernetes 1.15 (released 06/19/2019). This change will
finally removed it in Kubernetes 1.19 (planned for August 2020).

The original command has long since been replaced by a GA init phase:
`kubeadm init phase upload-config`

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-29 18:27:48 +03:00
Lubomir I. Ivanov
ceb768ccbd kubeadm: apply patches to static Pods
Add PatchStaticPod() in staticpod/utils.go

Apply patches to static Pods in:
- phases/controlplane/CreateStaticPodFiles()
- phases/etcd/CreateLocalEtcdStaticPodManifestFile() and
CreateStackedEtcdStaticPodManifestFile()

Add unit tests and update Bazel.
2020-06-26 02:14:47 +03:00
Lubomir I. Ivanov
144778db83 kubeadm: plumb the patches option trough init/join/upgrade
This changes adds the "patches" option in all places where
the "kustomize" option is already present.
2020-06-26 02:14:47 +03:00
Lubomir I. Ivanov
5506049b87 kubeadm: add logic for patching components in util/patches 2020-06-26 02:14:47 +03:00
Lubomir I. Ivanov
a8b31556c8 kubeadm: add the --experimental-patches flag in cmd/options 2020-06-26 02:14:46 +03:00
Rostislav M. Georgiev
709e3c3a83 kubeadm upgrade plan: component config state table
This change enables kubeadm upgrade plan to print a state table with
information regarding known component config API groups. Most importantly this
information includes current and preferred version for each group and an
indication if a manual user upgrade is required.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-24 16:47:15 +03:00
Rostislav M. Georgiev
9d6e2b923a kubeadm upgrade plan: Use internal types of the output API
`kubeadm upgrade plan` is using the external (currently `v1alpha1`) types of
the kubeadm output API to collect upgrade plans. This is counter intuitive
since code structure gets bound to the whatever version the output API is at.
In addition to that, the versioned API is used only in the very last stages of
a machine readable output (which is currently not implemented).

Hence, to increase flexibility and keep up with the standard Kubernetes
ecosystem practice, `kubeadm upgrade plan` is migrated to use the internal
types of the output API.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-24 16:47:15 +03:00
Kubernetes Prow Robot
cb0ef9e623
Merge pull request #92390 from neolit123/1.19-fix-long-upload-config-tests
kubeadm: remove negative test cases from TestUploadConfiguration
2020-06-24 04:55:31 -07:00
Kubernetes Prow Robot
a463b25c9d
Merge pull request #91980 from rosti/kubeadm-cc-manual-upgrade
kubeadm upgrade: Allow supplying hand migrated component configs
2020-06-23 09:35:42 -07:00
Lubomir I. Ivanov
bcc16b9c1e kubeadm: remove negative test cases from TestUploadConfiguration
UploadConfiguration() now always retries the underling API calls,
which can make TestUploadConfiguration run for a long time.

Remove the negative test cases, where errors are expected.
Negative test cases should be tested in app/util/apiclient,
where a short timeout / retry count should be possible for unit tests.
2020-06-22 22:14:11 +03:00
Rostislav M. Georgiev
1d2d15ee03 kubeadm upgrade: Allow supplying hand migrated component configs
Currently, kubeadm would refuse to perfom an upgrade (or even planing for one)
if it detects a user supplied unsupported component config version. Hence,
users are required to manually upgrade their component configs and store them
in the config maps prior to executing `kubeadm upgrade plan` or
`kubeadm upgrade apply`.

This change introduces the ability to use the `--config` option of the
`kubeadm upgrade plan` and `kubeadm upgrade apply` commands to supply a YAML
file containing component configs to be used in place of the existing ones in
the cluster upon upgrade.

The old behavior where `--config` is used to reconfigure a cluster is still
supported. kubeadm automatically detects which behavior to use based on the
presence (or absense) of kubeadm config types (API group
`kubeadm.kubernetes.io`).

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-22 16:29:51 +03:00
Lubomir I. Ivanov
94af045324 kubeadm: don't re-add an etcd member if it already exists for "join"
If an etcd member with the same address already exists, don't re-add it.
Instead, use the existing member list for creating the "initial cluster"
that is written for this etcd server instance static Pod.
2020-06-15 20:22:13 +03:00
SataQiu
800dd19fc2 increase robustness for kubeadm etcd operations
Signed-off-by: SataQiu <1527062125@qq.com>
2020-06-15 22:43:21 +08:00
Lubomir I. Ivanov
7ddd966ed2 kubeadm: mark --experimental-kustomize as deprecated 2020-06-11 04:57:13 +03:00
Xianglin Gao
04ef3628e3 refact CreateOrMutateConfigMap and MutateConfigMap with PollImmediate
Signed-off-by: Xianglin Gao <xianglin.gxl@alibaba-inc.com>
2020-06-11 00:31:22 +08:00
Rostislav M. Georgiev
5d0127493c kubeadm upgrade plan: don't load component configs
Component configs are used by kubeadm upgrade plan at the moment. However, they
can prevent kubeadm upgrade plan from functioning if loading of an unsupported
version of a component config is attempted. For that matter it's best to just
stop loading component configs as part of the kubeadm config load process.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-10 14:23:53 +03:00
Xianglin Gao
6d572ea9b7 Add retries for CreateOrUpdateRoleBinding
Signed-off-by: Xianglin Gao <xianglin.gxl@alibaba-inc.com>
2020-06-10 00:23:46 +08:00
Xianglin Gao
052eb7d9a5 Add retries for CreateOrUpdateRole
Signed-off-by: Xianglin Gao <xianglin.gxl@alibaba-inc.com>
2020-06-10 00:12:25 +08:00
Rostislav M. Georgiev
e7427c66f3 kubeadm: Merge getK8sVersionFromUserInput into enforceRequirements
`getK8sVersionFromUserInput` would attempt to load the config from a user
specified YAML file (via the `--config` option of `kubeadm upgrade plan` or
`kubeadm upgrade apply`). This is done in order to fetch the `KubernetesVersion`
field of the `ClusterConfiguration`. The complete config is then immediately
discarded. The actual config that is used during the upgrade process is fetched
from within `enforceRequirements`.

This, along with the fact that `getK8sVersionFromUserInput` is always called
immediately after `enforceRequirements` makes it possible to merge the two.
Merging them would help us simplify things and avoid future problems in
component config related patches.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-09 14:46:56 +03:00
Kubernetes Prow Robot
b8b4186a14
Merge pull request #90143 from neolit123/1.19-remove-cert-renew-api
kubeadm: remove usage of the "certificates" API for cert renewal
2020-06-05 11:35:43 -07:00
Kubernetes Prow Robot
b607c7cd52
Merge pull request #86070 from rosti/kubeadm-cc-user-configs-checksum-a
kubeadm: distinguish between generated and user supplied component configs
2020-06-03 05:44:18 -07:00
Kubernetes Prow Robot
40076c856e
Merge pull request #91179 from SataQiu/startup-probe-20200517
kubeadm: add startup probes for static Pods to protect slow starting containers
2020-06-02 18:10:31 -07:00
Rostislav M. Georgiev
5d6cf8ecd4 kubeadm: Distinguish between user supplied and generated component configs
Until now, users were always asked to manually convert a component config to a
version supported by kubeadm, if kubeadm is not supporting its version.
This is true even for configs generated with older kubeadm versions, hence
getting users to make manual conversions on kubeadm generated configs.
This is not appropriate and user friendly, although, it tends to be the most
common case. Hence, we sign kubeadm generated component configs stored in
config maps with a SHA256 checksum. If a configs is loaded by kubeadm from a
config map and has a valid signature it's considered "kubeadm generated" and if
a version migration is required, this config is automatically discarded and a
new one is generated.
If there is no checksum or the checksum is not matching, the config is
considered as "user supplied" and, if a version migration is required, kubeadm
will bail out with an error, requiring manual config migration (as it's today).
The behavior when supplying component configs on the kubeadm command line
does not change. Kubeadm would still bail out with an error requiring migration
if it can recognize their groups but not versions.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-06-01 17:57:53 +03:00
Kubernetes Prow Robot
774c9a6db6
Merge pull request #91349 from neolit123/1.19-fail-on-unrecognized-args
cmd/*: fail on unrecognized flags/arguments for component CLI
2020-05-30 00:27:53 -07:00
Kubernetes Prow Robot
2572066ac0
Merge pull request #91424 from prasadkatti/add_validate_etcd_tests
Add tests for ValidateEtcd
2020-05-28 16:37:53 -07:00
Monis Khan
fc4f91f10b cmd/*: fail on unrecognized flags/arguments for component CLI
In case a malformed flag is passed to k8s components
such as "–foo", where "–" is not an ASCII dash character,
the components currently silently ignore the flag
and treat it as a positional argument.

Make k8s components/commands exit with an error if a positional argument
that is not empty is found. Include a custom error message for all
components except kubeadm, as cobra.NoArgs is used in a lot of
places already (can be fixed in a followup).

The kubelet already handles this properly - e.g.:
'unknown command: "–foo"'

This change affects:
- cloud-controller-manager
- kube-apiserver
- kube-controller-manager
- kube-proxy
- kubeadm {alpha|config|token|version}
- kubemark

Signed-off-by: Monis Khan <mok@vmware.com>
Signed-off-by: Lubomir I. Ivanov <lubomirivanov@vmware.com>
2020-05-28 22:06:01 +03:00
Kubernetes Prow Robot
02637bb250
Merge pull request #91145 from tnqn/kubeadm-reset-error
kubeadm: skip removing last etcd member in reset phase
2020-05-27 15:04:01 -07:00
Prasad Katti
c253ccca00 Add tests for ValidateEtcd 2020-05-27 10:40:13 -07:00
Prasad Katti
a85fc1038c Add tests for ValidateURLs (kubeadm validation) 2020-05-26 20:31:04 -07:00
Prasad Katti
b5c08caa34 Add tests for ValidateSocketPath 2020-05-25 17:28:58 -07:00
Prasad Katti
a1ac30db40 Add a kubeadm ValidateNodeRegistrationOptions test 2020-05-24 14:18:41 -07:00
Rostislav M. Georgiev
def0db6a16 kubeadm: Remove unused constants
Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-05-22 17:10:27 +03:00
SataQiu
e04a2b3b26 kubeadm: add startup probes for static Pods to protect slow starting containers
Signed-off-by: SataQiu <1527062125@qq.com>
2020-05-21 11:12:36 +08:00
Prasad Katti
d7f769be3e Update kubeadm test TestMarkControlPlane
- Use a dummy nodename instead of OS hostname
- Inline toString() function
- Use backticks to wrap expected patch
- Remove redundant test name from error logs
2020-05-20 12:43:18 -07:00
Quan Tian
9cc416e7df kubeadm: do not remove the only remaining etcd member during reset
If this is the only remaining stacked etcd member in the cluster,
calling RemoveMember() is not needed.
2020-05-21 02:12:36 +08:00
Kubernetes Prow Robot
bb4a21161f
Merge pull request #90892 from xphoniex/fix-kubeadm-getting-stuck-alpine
kubeadm: move the "kubelet-start" phase after "kubeconfig" for "init"
2020-05-19 16:32:19 -07:00
Rostislav M. Georgiev
543f29be4e kubeadm: Reduce kubelet.DownloadConfig usage
kubelet.DownloadConfig is an old utility function which takes a client set and
a kubelet version, uses them to fetch the kubelet component config from a
config map, and places it in a local file. This function is simple to use, but
it is dangerous and unnecessary. Practically, in all cases the kubelet
configuration is present locally and does not need to be fetched from a config
map on the cluster (it just needs to be stored in a file).
Furthermore, kubelet.DownloadConfig does not use the kubeadm component configs
module in any way. Hence, a kubelet configuration fetched using it may not be
patched, validated, or otherwise, processed in any way by kubeadm other than
piping it to a file.

This patch replaces all but a single kubelet.DownloadConfig invocation with
equivalents that get the local copy of the kubelet component config and just
store it in a file. The sole remaining invocation covers the
`kubeadm upgrade node --kubelet-version` case.

In addition to that, a possible panic is fixed in kubelet.DownloadConfig and
it now takes the kubelet version parameter as string.

Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
2020-05-19 13:30:45 +03:00
Kubernetes Prow Robot
c8ecfc328d
Merge pull request #91158 from prasadkatti/master
[kubeadm] add tests for package `patchnode`
2020-05-18 13:33:58 -07:00
Prasad Katti
21a1d1d179 [kubeadm] add tests for patchnode 2020-05-18 10:06:06 -07:00