Skip to content

Field deletion doesn't work well in SSA #171

@mengqiy

Description

@mengqiy

k8s version is 1.19.1.

I first created the following by using kubectl apply --server-side -f backendconfig.yaml

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: bar
  namespace: default
spec:
  connectionDraining:
    drainingTimeoutSec: 30
  securityPolicy:
    name: bol-default-policy

The following is what has been created and persisted:

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  creationTimestamp: "2020-09-11T18:18:40Z"
  generation: 1
  managedFields:
  - apiVersion: cloud.google.com/v1
    fieldsType: FieldsV1
    fieldsV1:
      f:spec:
        f:connectionDraining:
          f:drainingTimeoutSec: {}
        f:securityPolicy:
          f:name: {}
    manager: kubectl
    operation: Apply
    time: "2020-09-11T18:18:40Z"
  name: bar
  namespace: default
  resourceVersion: "214762"
  selfLink: /apis/cloud.google.com/v1/namespaces/default/backendconfigs/bar
  uid: 8d90b477-994f-4091-b631-95f19ad10730
spec:
  connectionDraining:
    drainingTimeoutSec: 30
  securityPolicy:
    name: bol-default-policy

Then I tried to re-apply the following using kubectl apply --server-side -f backendconfig.yaml

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: bar
  namespace: default
spec:
  # <=========== connectionDraining field is removed.
  securityPolicy:
    name: bol-default-policy

I got error:

The BackendConfig "bar" is invalid: spec.connectionDraining: Invalid value: "null": spec.connectionDraining in body must be of type object: "null"

I also tried to re-apply the following using kubectl apply --server-side -f backendconfig.yaml

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: bar
  namespace: default
spec:
  connectionDraining: null  # <======= connectionDraining is set to null
  securityPolicy:
    name: bol-default-policy

I got the same error:

The BackendConfig "bar" is invalid: spec.connectionDraining: Invalid value: "null": spec.connectionDraining in body must be of type object: "null"

On the other hand, I tried to update the created object with kubectl replace -f backendconfig.yaml

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: bar
  namespace: default
spec:
  connectionDraining: null  # <======= connectionDraining is set to null
  securityPolicy:
    name: bol-default-policy

I got the same schema validation error as SSA above.

But if I run kubectl replace with the following, it can successfully remove the field w/o error.

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: bar
  namespace: default
spec:
  # <========== connectionDraining field is removed.
  securityPolicy:
    name: bol-default-policy

I have played with SMD v4 libary a bit, my understanding is that:
SMD v4 set the field as null in the merged object when it infers the user want to delete the field.
In this case, initially it is

spec:
  connectionDraining:
    drainingTimeoutSec: 30
  securityPolicy:
    name: bol-default-policy

Then I SSA:

spec:
  securityPolicy:
    name: bol-default-policy

In the apiserver, SMD v4 merged the object as the following before the object goes to the validation:

spec:
  connectionDraining: null
  securityPolicy:
    name: bol-default-policy

The OpenAPI schema validation rejects the object since the connectionDraining field is an object:

              connectionDraining:
                description: ConnectionDrainingConfig contains configuration for connection
                  draining. For now the draining timeout. May manage more settings
                  in the future.
                properties:
                  drainingTimeoutSec:
                    description: Draining timeout in seconds.
                    format: int64
                    type: integer
                type: object

Metadata

Metadata

Assignees

Labels

wg/api-expressionCategorizes an issue or PR as relevant to WG API Expression.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions