Open bborbe opened 6 years ago
Reproduce
Sample service:
apiVersion: v1
kind: Service
metadata:
labels:
app: kickstart
name: kickstart
namespace: kickstart
spec:
ports:
- name: web
port: 80
protocol: TCP
targetPort: http
selector:
app: kickstart
Apply service multiple times works
kubectl apply -f kickstart.yaml
kubectl apply -f kickstart.yaml
Read the service and apply again.
kubectl get svc kickstart -n kickstart -o yaml | kubectl apply -f -
kubectl apply -f kickstart.yaml
Now apply does not work any more.
The Service "kickstart" is invalid:
* metadata.resourceVersion: Invalid value: "": must be specified for an update
* spec.clusterIP: Invalid value: "": field is immutable
Remove the last-applied-configuration annotation for fix.
kubectl annotate svc kickstart -n kickstart kubectl.kubernetes.io/last-applied-configuration-
Now apply works again.
kubectl apply -f kickstart.yaml
Using patch would work but our NEW object is broken and lacking values:
ORIG: {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"creationTimestamp\":null,\"labels\":{\"app\":\"http-dump\"},\"name\":\"http-dump\",\"namespace\":\"http-dump\"},\"spec\":{\"ports\":[{\"name\":\"http\",\"port\":80,\"protocol\":\"TCP\",\"targetPort\":8080}],\"selector\":{\"app\":\"http-dump\"},\"type\":\"NodePort\"}}\n"},"creationTimestamp":"2018-05-14T19:41:13Z","labels":{"app":"http-dump"},"name":"http-dump","namespace":"http-dump","resourceVersion":"66799671","selfLink":"/api/v1/namespaces/http-dump/services/http-dump","uid":"c2cd756c-57ae-11e8-96a0-42010a84009c"},"spec":{"clusterIP":"10.15.57.176","externalTrafficPolicy":"Cluster","ports":[{"name":"http","nodePort":32721,"port":80,"protocol":"TCP","targetPort":8080}],"selector":{"app":"http-dump"},"sessionAffinity":"None","type":"NodePort"},"status":{"loadBalancer":{}}}
NEW: {"apiVersion":"v1","kind":"Service","metadata":{"creationTimestamp":null,"labels":{"app":"http-dump"},"name":"http-dump","namespace":"http-dump"},"spec":{"ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":8080}],"selector":{"app":"http-dump"},"type":"NodePort"},"status":{"loadBalancer":{}}}
PATCH: {"metadata":{"annotations":null,"creationTimestamp":null,"resourceVersion":null,"selfLink":null,"uid":null},"spec":{"clusterIP":null,"externalTrafficPolicy":null,"ports":[{"name":"http","port":80,"protocol":"TCP","targetPort":8080}],"sessionAffinity":null}}
one suggestion is "start with orig, mutate it to become new, then create a patch?"
Used Version 1.1.4