-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
add print-manifest flag to print addon manifests to STDOUT #109995
Conversation
cmd/kubeadm/app/cmd/init.go
Outdated
flagSet.BoolVar( | ||
&initOptions.printManifest, options.PrintManifest, initOptions.printManifest, | ||
"Print the addon manifests to STDOUT instead of install them.", | ||
) |
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.
i think we should not add the flag to the main init
or init phase addon
, but only to the addon phases:
init phase addon coredns --print-manifest
init phase addon kube-proxy --print-manifest
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. I will move the flag to the addon phases
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.
Print the addon manifests to STDOUT instead of install them.
->
Print the addon manifest to STDOUT instead of installing them.
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.
The plural form is correct here (with s / them) or we can remove "s" and have "it". We can adjust the message again once the rest of the code org is done.
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 for the PR @wangyysde
i've added a few comments.
basically what we want is the following:
- add the new flag only to the addon phases them self, but not to the parent
addon
command orinit
. Ensure*
addon functions can accept theprintManifest
bool flag, but do the printing on anio.Writer
and not always to STDOUT.
that seems like the easiest refactor.
please let me know if you have questions.
/cc @pacoxu
PTAL for reviews too if you have time.
/remove-area code-generation provider/gcp |
I have modified this PR. @neolit123 @pacoxu Could you review it again? Thks! |
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.
@wangyysde thanks for continuing to work on this.
added a few minor comments, but it seems we are going to be able to merge this soon.
fmt.Fprintf(out, "%s\n", []byte(CoreDNSServiceAccount)) | ||
return nil | ||
} | ||
|
||
if err := createCoreDNSAddon(coreDNSDeploymentBytes, coreDNSServiceBytes, coreDNSConfigMapBytes, client); err != nil { | ||
return err | ||
} |
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.
let's use the fmt.Println(out, ...)
instead of fmt.Println("[addons] Applied essential addon: CoreDNS")
on the line below (154), given we now have the proper target passed to this function.
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.
Ok .
if err := CreateServiceAccount(client); err != nil { | ||
return errors.Wrap(err, "error when creating kube-proxy service account") | ||
} | ||
func EnsureProxyAddon(cfg *kubeadmapi.ClusterConfiguration, localEndpoint *kubeadmapi.APIEndpoint, client clientset.Interface, out io.Writer, printManifest bool) 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.
let's remove this empty line (side cleanup)
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.
Thks.
} | ||
|
||
fmt.Println("[addons] Applied essential addon: kube-proxy") | ||
return nil | ||
} | ||
|
||
// CreateServiceAccount creates the necessary serviceaccounts that kubeadm uses/might use, if they don't already exist. | ||
func CreateServiceAccount(client clientset.Interface) error { | ||
// Create Sa, RBACRules or print manifests of them to out if printManifest is 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.
// Create Sa, RBACRules or print manifests of them to out if printManifest is true | |
// Create SA, RBACRules or print manifests of them to out if printManifest is 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.
Thks.
// CreateServiceAccount creates the necessary serviceaccounts that kubeadm uses/might use, if they don't already exist. | ||
func CreateServiceAccount(client clientset.Interface) error { | ||
// Create Sa, RBACRules or print manifests of them to out if printManifest is true | ||
func CreateSARBACRules(cmByte []byte, dsByte []byte, client clientset.Interface, out io.Writer, printManifest bool) 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.
can we make this function private. also maybe we can call it printOrCreateKubeProxyObjects()
?
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.
I have renamed the function to printOrCreateKubeProxyObjects
I have modified this PR. @neolit123 @pacoxu Could you review it again? Thks! |
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.
/lgtm
/approve
good job, thanks!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: neolit123, wangyysde 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 |
looks like some PRs just merged and this needs a quick rebase. |
so i tested it locally and there are some minor problems, but overall this is working as expected. 1. the client should not be needed when we print manifests
this can be avoided with a simple fix: diff --git a/cmd/kubeadm/app/cmd/phases/init/addons.go b/cmd/kubeadm/app/cmd/phases/init/addons.go
index c31eb779fd1..47fa070ae69 100644
--- a/cmd/kubeadm/app/cmd/phases/init/addons.go
+++ b/cmd/kubeadm/app/cmd/phases/init/addons.go
@@ -90,9 +90,13 @@ func getInitData(c workflow.RunData) (*kubeadmapi.InitConfiguration, clientset.I
return nil, nil, nil, errors.New("addon phase invoked with an invalid data struct")
}
cfg := data.Cfg()
- client, err := data.Client()
- if err != nil {
- return nil, nil, nil, err
+ var client clientset.Interface
+ var err error
+ if !printManifest {
+ client, err = data.Client()
+ if err != nil {
+ return nil, nil, nil, err
+ }
}
out := data.OutputWriter() 2. even if we pass --print-manifest the lines:
are printed. we should only print them if we are actually applying the addons. 3. when the manifests are printed there are extra new lines around the example - currently it's:
should be:
the idea is to have:
instead of:
|
Signed-off-by: wangyysde <[email protected]>
/test pull-kubernetes-e2e-kind |
@neolit123 @pacoxu
Thks. I have modified it.
This bug has be fixed. thks.
New lines have been omitted. |
/lgtm |
/hold cancel thanks again. |
/retest |
Signed-off-by: wangyysde [email protected]
What type of PR is this?
What this PR does / why we need it:
It can be useful to allow kubeadm users to skip addons but still be able to obtain the addon manifests that kubeadm will apply for version X. This PR add print-manifest flag to support printing addon manifests to STDOUT.
Which issue(s) this PR fixes:
Fixes kubernetes/kubeadm#2681
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: