Operators

Finalizers

Create a manifest for a Deployment with a Finalizer.

cat > finalizer-test.yaml<<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: finalizer-test
  namespace: myproject
  labels:
    app: finalizer-test
  finalizers:
    - finalizer.extensions/v1beta1  
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: finalizer-test
    spec:
      serviceAccountName: useroot
      containers:
        - name: hieveryone
          image: quay.io/coreostrainme/hieveryone:1.0.0
          imagePullPolicy: Always
          ports:
            - name: helloworldport
              containerPort: 80
EOF

Create the Deployment.

oc create -f finalizer-test.yaml

Verify the Deployment has been created.

oc get deploy
oc get pods

Attempt to delete the Deployment.

oc delete deployment finalizer-test

Observe the Deployment still exits and has been updated with the deletionGracePeriodSeconds and deletionTimestamp fields.

oc get deployment finalizer-test -o yaml | grep 'deletionGracePeriodSeconds\|deletionTimestamp'

Attempt to scale the Deployment up and down. Although status is updated, pods will not be created/deleted.

oc scale deploy finalizer-test --replicas=5
oc scale deploy finalizer-test --replicas=1
oc get deploy
oc get pods

Update the Deployment with the Finalizer value unset.

cat > finalizer-test-remove.yaml<<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: finalizer-test
  namespace: myproject
  labels:
    app: finalizer-test
  finalizers:
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: finalizer-test
    spec:
      serviceAccountName: useroot
      containers:
        - name: hieveryone
          image: quay.io/coreostrainme/hieveryone:1.0.0
          imagePullPolicy: Always
          ports:
            - name: helloworldport
              containerPort: 80
EOF

Replace the Deployment.

oc replace -f finalizer-test-remove.yaml

The Deployment will now be deleted.

oc get deploy
oc get pods

See the following:

Deployment Controller (DeletionTimestamp != nil)

SyncStatusOnly Method