-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
kubeadm: Refactor InitConfiguration init APIs #73701
Conversation
/priority important-longterm |
77700e3
to
22f843a
Compare
This one should be ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
this looks good thanks @rosti
will leave the lgtm to another set of 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rosti this looks great! thanks!
I left some comments; I'm looking forward to can get this merged asap!
/approve
@@ -80,7 +80,7 @@ func newCmdUserKubeConfig(out io.Writer) *cobra.Command { | |||
} | |||
|
|||
// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should reflect the fact the we are not loading config file
cmd/kubeadm/app/cmd/join.go
Outdated
@@ -647,7 +647,7 @@ func fetchInitConfiguration(tlsBootstrapCfg *clientcmdapi.Config) (*kubeadmapi.I | |||
} | |||
|
|||
// Fetches the init configuration | |||
initConfiguration, err := configutil.FetchConfigFromFileOrCluster(tlsClient, os.Stdout, "join", "", true) | |||
initConfiguration, err := configutil.FetchConfigFromCluster(tlsClient, os.Stdout, "join", true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, not in the scope of this PR but interesting for a potential follow issue/PR.
What we really need here is the ClusterConfiguration
only, because the components configs are not used by join and the data for the current node are extracted from the Join configuration.
Having a method that allows fetching the ClusterConfiguration
only could be beneficial in many ways:
- join became resilient to the fact the kube-proxy add-on exists or not (if I'm not wrong @neolit123 is working on this)
- it is possible to get rid of the
newControlPlane
flag in fetch config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally FetchConfigFromCluster
would be renamed to FetchClusterConfiguration
and would return ClusterConfiguration only. getNodeRegistration
and getAPIEndpoint
will become public separate functions.
Another way to tackle this is to introduce an interface, that has GetClientConfiguration()
, GetNodeRegistration()
and GetLocalAPIEndpoint()
. InitConfiguration will implement this, so it will be straightforward to use. Also, there will be an internal implementation, that takes kubeconfig and/or JoinConfiguration and then implement the interface by fetching stuff from the cluster or JoinConfiguration. This approach has the benefit of replacing InitConfiguration in most places with a single type and of adding caching (so that we fetch ClusterConfiguration only once for example).
I am experimenting with both approaches, but the first code will probably become available in the 1.15 time frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
became resilient to the fact the kube-proxy add-on exists or not (if I'm not wrong @neolit123 is working on this)
waiting on the join phases work to finish.
but i think we might have a problem related to that.
i think the original reason to fetch the component config for kubeproxy was to be able to perform specific preflight checks on the joining node (was it about IPVS?). if we fetch cluster config only, these preflight checks will have to be removed (or made optional, somehow)
cmd/kubeadm/app/cmd/reset.go
Outdated
@@ -299,7 +299,7 @@ func resetConfigDir(configPathDir, pkiPathDir string) { | |||
|
|||
func resetDetectCRISocket(client clientset.Interface) (string, error) { | |||
// first try to connect to the cluster for the CRI socket | |||
cfg, err := configutil.FetchConfigFromFileOrCluster(client, os.Stdout, "reset", "", false) | |||
cfg, err := configutil.FetchConfigFromCluster(client, os.Stdout, "reset", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another note for follow-up PR.
We should avoid fetching the config twice in reset 😢
} | ||
|
||
// FetchConfigFromCluster fetches configuration from a ConfigMap in the cluster | ||
func FetchConfigFromCluster(client clientset.Interface, w io.Writer, logPrefix string, newControlPlane bool) (*kubeadmapi.InitConfiguration, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about using FetchInitConfigurationFromCluster
instead of FetchConfigFromCluster
(same pattern of LoadInitConfigurationFromFile
or DefaultedInitConfiguration
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally I envisioned FetchConfigFromCluster
to be reduced to returning ClusterConfiguration
only. However I am still not fully committed on this approach and this probably won't happen in 1.14, so I'll rename it to contain Init
in its name.
// Then the external, versioned configuration is defaulted and converted to the internal type. | ||
// Right thereafter, the configuration is defaulted again with dynamic values (like IP addresses of a machine, etc) | ||
// Lastly, the internal config is validated and returned. | ||
func ConfigFileAndDefaultsToInternalConfig(cfgPath string, defaultversionedcfg *kubeadmapiv1beta1.InitConfiguration) (*kubeadmapi.InitConfiguration, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about renaming into LoadOrDefaultInitConfiguration
or something similar (that uses InitConfiguration
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done by @bruceauyeung in a yet to be merged PR #68595 .
It's better if it goes in this one though as it's more tied to the subject at hand.
@fabriziopandini @bruceauyeung WDYT?
22f843a
to
c9a4d35
Compare
Currently ConfigFileAndDefaultsToInternalConfig and FetchConfigFromFileOrCluster are used to default and load InitConfiguration from file or cluster. These two APIs do a couple of completely separate things depending on how they were invoked. In the case of ConfigFileAndDefaultsToInternalConfig, an InitConfiguration could be either defaulted with external override parameters, or loaded from file. With FetchConfigFromFileOrCluster an InitConfiguration is either loaded from file or from the config map in the cluster. The two share both some functionality, but not enough code. They are also quite difficult to use and sometimes even error prone. To solve the issues, the following steps were taken: - Introduce DefaultedInitConfiguration which returns defaulted version agnostic InitConfiguration. The function takes InitConfiguration for overriding the defaults. - Introduce LoadInitConfigurationFromFile, which loads, converts, validates and defaults an InitConfiguration from file. - Introduce FetchInitConfigurationFromCluster that fetches InitConfiguration from the config map. - Reduce, when possible, the usage of ConfigFileAndDefaultsToInternalConfig by replacing it with DefaultedInitConfiguration or LoadInitConfigurationFromFile invocations. - Replace all usages of FetchConfigFromFileOrCluster with calls to LoadInitConfigurationFromFile or FetchInitConfigurationFromCluster. - Delete FetchConfigFromFileOrCluster as it's no longer used. - Rename ConfigFileAndDefaultsToInternalConfig to LoadOrDefaultInitConfiguration in order to better describe what the function is actually doing. Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
c9a4d35
to
51197e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @rosti
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini, neolit123, rosti The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Currently
ConfigFileAndDefaultsToInternalConfig
andFetchConfigFromFileOrCluster
are used to default and loadInitConfiguration
from file or cluster. These two APIs do a couple of completely separate things depending on how they were invoked.In the case of
ConfigFileAndDefaultsToInternalConfig
, anInitConfiguration
could be either defaulted with external override parameters, or loaded from file.With
FetchConfigFromFileOrCluster
anInitConfiguration
is either loaded from file or from the config map in the cluster.The two share both some functionality, but not enough code. They are also quite difficult to use and sometimes even error prone.
To solve the issues, the following steps were taken:
Introduce
DefaultedInitConfiguration
which returns defaulted version agnosticInitConfiguration
. The function takesInitConfiguration
for overriding the defaults.Introduce
LoadInitConfigurationFromFile
, which loads, converts, validates and defaults anInitConfiguration
from file.Introduce
FetchConfigFromCluster
that fetchesInitConfiguration
from the config map.Reduce, when possible, the usage of
ConfigFileAndDefaultsToInternalConfig
by replacing it withDefaultedInitConfiguration
orLoadInitConfigurationFromFile
invocations.Replace all usages of
FetchConfigFromFileOrCluster
with calls toLoadInitConfigurationFromFile
orFetchConfigFromCluster
whenever needed.Delete
FetchConfigFromFileOrCluster
as it's no longer used.Which issue(s) this PR fixes:
Refs kubernetes/kubeadm#1296
Special notes for your reviewer:
/cc @kubernetes/sig-cluster-lifecycle-pr-reviews
/area kubeadm
/assign @fabriziopandini
/assign @neolit123
Does this PR introduce a user-facing change?: