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
karmadactl
: Fixed --namespace
flag of init
command not work issue.
#1416
Conversation
Welcome @sayaoailun! It looks like this is your first PR to karmada-io/karmada 🎉 |
Thanks, @sayaoailun for the feedback on this. How to reproduce it? Could you please give more details? |
When init Karmada, set The
|
@@ -268,7 +269,7 @@ func (i *CommandInitOption) makeKarmadaKubeControllerManagerDeployment() *appsv1 | |||
"--controllers=namespace,garbagecollector,serviceaccount-token", | |||
"--kubeconfig=/etc/kubeconfig", | |||
"--leader-elect=true", | |||
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace), | |||
fmt.Sprintf("--leader-elect-resource-namespace=%s", util.NamespaceKarmadaSystem), |
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.
Should this value also be configurable?
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.
Maybe it should be. I don't know the exact scope of influence.
As far as I know, The related code is as follows:
karmada/pkg/karmadactl/cmdinit/karmada/deploy.go
Lines 42 to 49 in 0b73c6b
// create namespace | |
if _, err := clientSet.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{ | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: namespace, | |
}, | |
}, metav1.CreateOptions{}); err != nil { | |
klog.Exitln(err) | |
} |
karmada/pkg/karmadactl/cmdinit/karmada/deploy.go
Lines 167 to 183 in 0b73c6b
aaService := &corev1.Service{ | |
TypeMeta: metav1.TypeMeta{ | |
APIVersion: "v1", | |
Kind: "Service", | |
}, | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: "karmada-aggregated-apiserver", | |
Namespace: namespace, | |
}, | |
Spec: corev1.ServiceSpec{ | |
Type: corev1.ServiceTypeExternalName, | |
ExternalName: fmt.Sprintf("karmada-aggregated-apiserver.%s.svc.cluster.local", namespace), | |
}, | |
} | |
if _, err := clientSet.CoreV1().Services(namespace).Create(context.TODO(), aaService, metav1.CreateOptions{}); err != nil { | |
return err | |
} |
karmada/pkg/karmadactl/cmdinit/karmada/deploy.go
Lines 191 to 211 in 0b73c6b
aaAPIService := &apiregistrationv1.APIService{ | |
TypeMeta: metav1.TypeMeta{ | |
APIVersion: "v1", | |
Kind: "APIService", | |
}, | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: aaAPIServiceObjName, | |
Labels: map[string]string{"app": "karmada-aggregated-apiserver", "apiserver": "true"}, | |
}, | |
Spec: apiregistrationv1.APIServiceSpec{ | |
InsecureSkipTLSVerify: true, | |
Group: "cluster.karmada.io", | |
GroupPriorityMinimum: 2000, | |
Service: &apiregistrationv1.ServiceReference{ | |
Name: "karmada-aggregated-apiserver", | |
Namespace: namespace, | |
}, | |
Version: "v1alpha1", | |
VersionPriority: 10, | |
}, | |
} |
The above code is about hard coded namespace karmada-system
in karmada which is created during karmada init.
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace), |
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace), |
The above code need the namespace which should be created in karmada during init, but now the namespace isn't created in karmada.
If the value should be configurable, maybe we can replace the hard coded namespace karmada-system
?e.g.
const namespace = "karmada-system" |
If you think it's OK, I can try to make the change.
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 what you're saying is quite reasonable.
These are actually two different changes, can you take them apart?
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, then if this PR can be merged, I'll make some change base on it to replace the hard coded namespace karmada-system
in karmada.
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 can't get why we need to hard code the namespace here.
It's beyond the scope of this PR, right? (If yes, I recommend filing another PR for it.)
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.
ping @sayaoailun
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 can't get why we need to hard code the namespace here. It's beyond the scope of this PR, right? (If yes, I recommend filing another PR for it.)
OK, new PR after this PR.
This PR is about custom namespace in host cluster.
Next PR is about the hard coded namespace in Karmada.
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's the benefit to hard-coding the --leader-elect-resource-namespace
? Or, what's the problem if we put the leader election resource under the namespace i.Namespace
?
I think this PR is focusing on solving -n
doesn't work issue, is it the mandatory part of the solution?
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.
Or, what's the problem if we put the leader election resource under the namespace
i.Namespace
?
For now, the namespace i.Namespace
was not created in Karmada but the hard coded namespace karamda-system
. When i.Namespace
is not set as karamda-system
, KarmadaKubeControllerManager
and KarmadaScheduler
couldn't create the lease object.
/cc @prodanlabs |
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.
There are two same commit messages.
The modification LGTM.
Have you tested with another namespace except karmada-system
on your local site?
Yes, I tested with another namespace. By the way, should I merge the two commits into one? |
I think it's better. |
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
/assign @RainbowMango @prodanlabs
@@ -28,7 +28,7 @@ import ( | |||
const namespace = "karmada-system" | |||
|
|||
// InitKarmadaResources Initialize karmada resource | |||
func InitKarmadaResources(dir, caBase64 string) error { | |||
func InitKarmadaResources(dir, caBase64 string, externalNamespace string) 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.
func InitKarmadaResources(dir, caBase64 string, externalNamespace string) error { | |
func InitKarmadaResources(dir, caBase64 string, systemNamespace string) error { |
I suggest renaming the parameter name to systemNamespace
, because there is no concept of external
or internal
here.
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.
karmada/pkg/karmadactl/cmdinit/karmada/deploy.go
Lines 176 to 179 in 867160a
Spec: corev1.ServiceSpec{ | |
Type: corev1.ServiceTypeExternalName, | |
ExternalName: fmt.Sprintf("karmada-aggregated-apiserver.%s.svc.cluster.local", externalNamespace), | |
}, |
It's just like the external service above.
karmada/pkg/karmadactl/cmdinit/karmada/deploy.go
Lines 80 to 95 in 867160a
// create webhook configuration | |
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/webhook-configuration.yaml | |
klog.Info("Create MutatingWebhookConfiguration mutating-config.") | |
if err = createMutatingWebhookConfiguration(clientSet, mutatingConfig(caBase64, externalNamespace)); err != nil { | |
klog.Exitln(err) | |
} | |
klog.Info("Create ValidatingWebhookConfiguration validating-config.") | |
if err = createValidatingWebhookConfiguration(clientSet, validatingConfig(caBase64, externalNamespace)); err != nil { | |
klog.Exitln(err) | |
} | |
// karmada-aggregated-apiserver | |
if err = initAPIService(clientSet, restConfig, externalNamespace); err != nil { | |
klog.Exitln(err) | |
} |
It's the namespace out of Karmada, which is used for webhook and karmada-aggregated-apiserver in Karmada.
The external
and internal
are for Karmada.
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 don't think so.
The namespace is used to specify the location of the service
(karmada-webhook, karmada-aggregate-apiserver) which is supposed in the Karmada system namespace by default.
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.
karmada/pkg/karmadactl/cmdinit/karmada/deploy.go
Lines 167 to 180 in 867160a
aaService := &corev1.Service{ | |
TypeMeta: metav1.TypeMeta{ | |
APIVersion: "v1", | |
Kind: "Service", | |
}, | |
ObjectMeta: metav1.ObjectMeta{ | |
Name: "karmada-aggregated-apiserver", | |
Namespace: namespace, | |
}, | |
Spec: corev1.ServiceSpec{ | |
Type: corev1.ServiceTypeExternalName, | |
ExternalName: fmt.Sprintf("karmada-aggregated-apiserver.%s.svc.cluster.local", externalNamespace), | |
}, | |
} |
The namespace is karmada-system
in Karmada which is hard coded.
The externalNamespace is custom namespace in host cluster where Karmada is deloyed.
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.
Yeah, I get what you mean. Once user specified the customized namespace by --namespace
, like myns
, which means:
- Installing Karmada components to the
myns
namespace onhost
cluster. (As well as the services...) - Karmada will use the
myns
as the system namespace to store some configuration resources, likeservice/karmada-aggregated-apiserver
.
Are you agree with that? Personally, I don't like to identify the namespace by internal
or external
as I think it brings a bit of confusion.
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.
- Karmada will use the
myns
as the system namespace to store some configuration resources, likeservice/karmada-aggregated-apiserver
.
For now, Karmada will use the hard coded namespace karmada-system
as the system namespace to store some configuration resources, like service/karmada-aggregated-apiserver
, not myns
. The resources created in karmada-system
in Karmada referance the resources created in myns
in host cluster.
Anyway, I'll make the change.
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.
Yeah, you are right. Seems we have a lot of things to do.
Hi @sayaoailun , Thanks for doing this. For other optimization work, please feel free to file a new PR. |
I checked the |
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 one question otherwise looks good to me.
@@ -268,7 +269,7 @@ func (i *CommandInitOption) makeKarmadaKubeControllerManagerDeployment() *appsv1 | |||
"--controllers=namespace,garbagecollector,serviceaccount-token", | |||
"--kubeconfig=/etc/kubeconfig", | |||
"--leader-elect=true", | |||
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace), | |||
fmt.Sprintf("--leader-elect-resource-namespace=%s", util.NamespaceKarmadaSystem), |
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's the benefit to hard-coding the --leader-elect-resource-namespace
? Or, what's the problem if we put the leader election resource under the namespace i.Namespace
?
I think this PR is focusing on solving -n
doesn't work issue, is it the mandatory part of the solution?
Hi @XiShanYongYe-Chang There is a failling test |
I will take a look. |
Hi @sayaoailun I made a copy of your commit at RainbowMango@b5a0160 Can you do it again and push it to your |
I rebased my |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango 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 |
/lgtm
There is a By the way, here is the PR workflow, it might be good for you. |
This PR will be merged automatically after testing is done. Welcome @sayaoailun |
Maybe I don't have permission? I didn't see it just now.
@RainbowMango I wonder how this happend. My steps are as follows: git fetch upstream
git rebase upstream/master The merge commit seems to be I don't know how this merge commit is related to this PR.
Maybe this is the reason? |
Hi @sayaoailun, remember to pick this commit to branch release-1.0 and release-1.1. |
No, we can't reopen a merged PR. |
@RainbowMango I mean PR closed before PR merged. |
@XiShanYongYe-Chang Done. |
cherry-pick #1416: `karmadactl`: Fixed `--namespace` flag of `init` command not work issue.
cherry-pick #1416: `karmadactl`: Fixed `--namespace` flag of `init` command not work issue.
Signed-off-by: sayaoailun guojianwei007@126.com
What type of PR is this?
/kind bug
What this PR does / why we need it:
The flag
-n
of karmadactl doesn't work as expectedWhich issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: