mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Set namespace when using kubectl create service
This commit is contained in:
parent
dd95f3ab5a
commit
d1e95a07b2
@ -72,6 +72,7 @@ type ServiceOptions struct {
|
||||
FieldManager string
|
||||
CreateAnnotation bool
|
||||
Namespace string
|
||||
EnforceNamespace bool
|
||||
|
||||
Client corev1client.CoreV1Interface
|
||||
DryRunStrategy cmdutil.DryRunStrategy
|
||||
@ -105,7 +106,7 @@ func (o *ServiceOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
||||
return err
|
||||
}
|
||||
|
||||
o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -173,13 +174,19 @@ func (o *ServiceOptions) createService() (*corev1.Service, error) {
|
||||
selector := map[string]string{}
|
||||
selector["app"] = o.Name
|
||||
|
||||
namespace := ""
|
||||
if o.EnforceNamespace {
|
||||
namespace = o.Namespace
|
||||
}
|
||||
|
||||
service := corev1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: o.Name,
|
||||
Labels: labels,
|
||||
Name: o.Name,
|
||||
Labels: labels,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: corev1.ServiceSpec{
|
||||
Type: corev1.ServiceType(o.Type),
|
||||
Type: o.Type,
|
||||
Selector: selector,
|
||||
Ports: ports,
|
||||
ExternalName: o.ExternalName,
|
||||
|
Loading…
Reference in New Issue
Block a user