Namespace has no effect when exposing deployment with --dry-run=client
This is how to reproduce.
$ kubectl create ns testns
$ kubectl -n testns create deployment test-deploy --image=nginx
$ kubectl -n testns expose deployment.apps/test-deploy --port=80 --dry-run=client -o yaml
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: test-deploy
name: test-deploy
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: test-deploy
status:
loadBalancer: {}
If --dry-run=client is not specified, namespace element is contained in the yaml.
Kubernetes-commit: 8d83dfe2075be68344a633418de7ef81e1dd5957
This commit is contained in:
parent
693dcc3ff8
commit
3c3bc4f5e8
|
|
@ -335,6 +335,9 @@ func (o *ExposeServiceOptions) RunExpose(cmd *cobra.Command, args []string) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.DryRunStrategy == cmdutil.DryRunClient {
|
if o.DryRunStrategy == cmdutil.DryRunClient {
|
||||||
|
if meta, err := meta.Accessor(object); err == nil && o.EnforceNamespace {
|
||||||
|
meta.SetNamespace(o.Namespace)
|
||||||
|
}
|
||||||
return o.PrintObj(object, o.Out)
|
return o.PrintObj(object, o.Out)
|
||||||
}
|
}
|
||||||
if err := util.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), object, scheme.DefaultJSONEncoder()); err != nil {
|
if err := util.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), object, scheme.DefaultJSONEncoder()); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package expose
|
package expose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -168,6 +167,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
Type: corev1.ServiceTypeLoadBalancer,
|
Type: corev1.ServiceTypeLoadBalancer,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -200,6 +200,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
SessionAffinity: corev1.ServiceAffinityClientIP,
|
SessionAffinity: corev1.ServiceAffinityClientIP,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -231,7 +232,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
ClusterIP: "10.10.10.10",
|
ClusterIP: "10.10.10.10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: "service /foo exposed",
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -263,7 +264,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
ClusterIP: corev1.ClusterIPNone,
|
ClusterIP: corev1.ClusterIPNone,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: "service/foo exposed",
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -289,7 +290,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
ClusterIP: corev1.ClusterIPNone,
|
ClusterIP: corev1.ClusterIPNone,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: "service/foo exposed",
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -320,6 +321,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
Selector: map[string]string{"func": "stream"},
|
Selector: map[string]string{"func": "stream"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -396,6 +398,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
Selector: map[string]string{"svc": "fromfoo"},
|
Selector: map[string]string{"svc": "fromfoo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
expected: "service/fromfoo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -466,6 +469,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
Selector: map[string]string{"svc": "fromfoo"},
|
Selector: map[string]string{"svc": "fromfoo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
expected: "service/fromfoo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -559,7 +563,7 @@ func TestRunExposeService(t *testing.T) {
|
||||||
ClusterIP: "10.10.10.10",
|
ClusterIP: "10.10.10.10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: "service /foo exposed",
|
expected: "service/foo exposed (dry run)",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -591,7 +595,39 @@ func TestRunExposeService(t *testing.T) {
|
||||||
ClusterIP: corev1.ClusterIPNone,
|
ClusterIP: corev1.ClusterIPNone,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: "service/foo exposed",
|
expected: "service/foo exposed (dry run)",
|
||||||
|
status: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "namespace-yaml",
|
||||||
|
args: []string{"service", "baz"},
|
||||||
|
ns: "testns",
|
||||||
|
calls: map[string]string{
|
||||||
|
"GET": "/namespaces/testns/services/baz",
|
||||||
|
"POST": "/namespaces/testns/services",
|
||||||
|
},
|
||||||
|
input: &corev1.Service{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "testns", ResourceVersion: "12"},
|
||||||
|
Spec: corev1.ServiceSpec{
|
||||||
|
Selector: map[string]string{"app": "go"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "type": "LoadBalancer", "dry-run": "client", "output": "yaml"},
|
||||||
|
output: &corev1.Service{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
|
||||||
|
Spec: corev1.ServiceSpec{
|
||||||
|
Ports: []corev1.ServicePort{
|
||||||
|
{
|
||||||
|
Protocol: corev1.ProtocolUDP,
|
||||||
|
Port: 14,
|
||||||
|
TargetPort: intstr.FromInt(14),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Selector: map[string]string{"func": "stream"},
|
||||||
|
Type: corev1.ServiceTypeLoadBalancer,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: "namespace: testns",
|
||||||
status: 200,
|
status: 200,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -629,8 +665,9 @@ func TestRunExposeService(t *testing.T) {
|
||||||
cmd.Run(cmd, test.args)
|
cmd.Run(cmd, test.args)
|
||||||
|
|
||||||
out := buf.String()
|
out := buf.String()
|
||||||
if _, ok := test.flags["dry-run"]; ok {
|
|
||||||
test.expected = fmt.Sprintf("service/%s exposed (dry run)", test.flags["name"])
|
if test.expected == "" {
|
||||||
|
t.Errorf("%s: Invalid test case. Specify expected result.\n", test.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(out, test.expected) {
|
if !strings.Contains(out, test.expected) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue