kubernetes/pkg/api
Tim Hockin 73503a4936 Fix a small regression in Service updates
Prior to 1.22 a user could change NodePort values within a service
during an update, and the apiserver would allocate values for any that
were not specified.

Consider a YAML like:

```
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  type: NodePort
  ports:
  - name: p
    port: 80
  - name: q
    port: 81
  selector:
    app: foo
```

When this is created, nodeport values will be allocated for each port.
Something like:

```
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  clusterIP: 10.0.149.11
  type: NodePort
  ports:
  - name: p
    nodePort: 30872
    port: 80
    protocol: TCP
    targetPort: 9376
  - name: q
    nodePort: 31310
    port: 81
    protocol: TCP
    targetPort: 81
  selector:
    app: foo
```

If the user PUTs (kubectl replace) the original YAML, we would see that
`.nodePort = 0`, and allocate new ports.  This was ugly at best.

In 1.22 we fixed this to not allocate new values if we still had the old
values, but instead re-assign them.  Net new ports would still be seen
as `.nodePort = 0` and so new allocations would be made.

This broke a corner case as follows:

Prior to 1.22, the user could PUT this YAML:

```
apiVersion: v1
kind: Service
metadata:
  name: foo
spec:
  type: NodePort
  ports:
  - name: p
    nodePort: 31310 # note this is the `q` value
    port: 80
  - name: q
    # note this nodePort is not specified
    port: 81
  selector:
    app: foo
```

The `p` port would take the `q` port's value.  The `q` port would be
seen as `.nodePort = 0` and a new value allocated.  In 1.22 this results
in an error (duplicate value in `p` and `q`).

This is VERY minor but it is an API regression, which we try to avoid,
and the fix is not too horrible.

This commit adds more robust testing of this logic.
2021-08-30 12:42:17 -07:00
..
endpoints/testing Move endpoints test-helper funcs to a package 2021-07-01 18:26:45 -07:00
legacyscheme hack/update-bazel.sh 2021-02-28 15:17:29 -08:00
persistentvolume Use cmp.Diff instead of diff.Object* in pkg/api 2021-03-20 21:40:34 +08:00
persistentvolumeclaim Add DataSourceRef field to PVC spec 2021-07-06 21:17:41 -04:00
pod Mention seccomp annotation removal in v1.25 2021-08-16 17:02:54 +02:00
podsecuritypolicy Merge pull request #100885 from enj/enj/i/auth_owners 2021-04-12 22:18:49 -07:00
service Fix a small regression in Service updates 2021-08-30 12:42:17 -07:00
testing Merge pull request #101711 from hbagdi/ingressclass-namespaced-params-beta 2021-06-29 17:07:03 -07:00
v1 Prune stale entries from OWNERS files 2021-04-13 20:54:50 -04:00
OWNERS Updated OWNERS files to include link to docs 2019-02-04 22:33:12 +01:00