Change:
Hey Guys , I try to use the option --override with kubectl expose . First i did this and it work : Now i want to add another service with kubectl expose and this command does not work I have this error If i remove --overrides the command work . `
/sig cli
expose tries to convert version from "v1" to "_internal" which is not registered. This is the reason that the function doesn't works. == "" 316 if inline := cmdutil.GetFlagString(cmd, "overrides"); len(inline) 0 { 317 object, err = cmdutil.Merge(scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...), object, inline) 318 if err != nil { 319 return err 320 } 321 } === 156 // LegacyCodec encodes output to a given API versions, and decodes output into the internal form from 157 // any recognized source. The returned codec will always encode output to JSON. If a type is not 158 // found in the list of versions an error will be returned. 159 // 160 // This method is deprecated - clients and servers should negotiate a serializer by mime-type and 161 // invoke CodecForVersions. Callers that need only to read data should use UniversalDecoder(). 162 // 163 // TODO: make this call exist only in pkg/api, and initialize it with the set of default versions. 164 // All other callers will be forced to request a Codec directly. 165 func (f CodecFactory) LegacyCodec(version ) runtime.Codec { 166 return versioning.NewDefaultingCodecForScheme(f.scheme, f.legacySerializer, f.universal, schema.GroupVersions(version), runtime.InternalGroupVersioner) 167 }
kubectl help expose Expose a resource as a new Kubernetes service. Possible resources include (case insensitive): pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs) In order to control the scope, I only register them as un-versioned type in the fix.

Discussion:
} if inline := cmdutil.GetFlagString(cmd, "overrides"); len(inline) > 0 { <del> object, err = cmdutil.Merge(scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...), object, inline) </del> <ins> codec := runtime.NewCodec(scheme.DefaultJSONEncoder(), scheme.Codecs.UniversalDecoder(scheme.Scheme.PrioritizedVersionsAllGroups()...)) object, err = cmdutil.Merge(codec, object, inline) </ins> if err != nil { return err }

# Post-condition: Only the default kubernetes services exist kube::test::get_object_assert services "{{range.items}}{{$id_field}}:{{end}}" 'kubernetes:' <ins> ### Create deployent and service # Pre-condition: no deployment exists kube::test::wait_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" '' # Command kubectl run testmetadata --image=nginx --replicas=2 --port=80 --expose --service-overrides='{ "metadata": { "annotations": { "zone-context": "home" } } } ' # Check result kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" 'testmetadata:' kube::test::get_object_assert 'service testmetadata' "{{.metadata.annotations}}" "map[zone-context:home]" ### Expose deployment as a new service # Command kubectl expose deployment testmetadata  --port=1000 --target-port=80 --type=NodePort --name=exposemetadata --overrides='{ "metadata": { "annotations": { "zone-context": "work" } } } ' # Check result kube::test::get_object_assert 'service exposemetadata' "{{.metadata.annotations}}" "map[zone-context:work]" # Clean-Up # Command kubectl delete service exposemetadata testmetadata "${kube_flags[@]}" if [[ "${WAIT_FOR_DELETION:-}" == "true" ]]; then kube::test::wait_object_assert services "{{range.items}}{{$id_field}}:{{end}}" 'kubernetes:' fi kubectl delete deployment testmetadata "${kube_flags[@]}" if [[ "${WAIT_FOR_DELETION:-}" == "true" ]]; then kube::test::wait_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" '' fi </ins> set +o nounset set +o errexit }