Description
Describe the bug
Configurator purges all the unused CustomConfigMap (CCM) revisions that were once referenced by a deployment or statefulset revision. Based on the revision history configured for a deployment/statefulset, Kubernetes automatically removes the unused deployment/statefulset revisions. If a CCM version was referenced in one of those unused deployment/statefulset revisions, then Configurator purges those unused CCMs periodically (once in every 15 mins). However, if a CCM has never been referenced in any of the deployment/statefulset revisions from the time of its creation, then Configurator does not purge those CCM revisions.
To Reproduce
Steps to reproduce the behavior:
1.Create a file named ConfigMap.yaml with the below contents and create a ConfigMap.
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-config
data:
# property-like keys; each key maps to a simple value
player_initial_lives: "3"
ui_properties_file_name: "user-interface.properties"
# file-like keys
game.properties: |
android.apk=free fire,bgmi
computer=stambled guys
user-interface.properties: |
color.good=purple
color.bad=yellow
allow.textmode=tru
$ kubectl apply -f ConfigMap.yaml
2.Edit the contents of the ConfigMap and save the ConfigMap. This will create a new CCM revision.
$ kubectl edit cm demo-config
3.List the CCM. It will show the 2 CCM versions.
$ kubectl get ccm
NAME AGE
demo-config-ifoiu 28s
demo-config-sg1cl 3m30s
4.Wait for 15 minutes. After 15 minutes, the automatic purge functionality is invoked. But it doesn't delete the unused CCM versions.
5.List the CCM again. Note that there are 2 CCM revisions still.
$ kubectl get ccm
NAME AGE
demo-config-ifoiu 14m
demo-config-sg1cl 17m
6.Create a new ConfigMap with the below contents.
$ vi ConfigMap-2.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: demo2-config
data:
names: |
paul
peter
$ kubectl apply -f ConfigMap-2.yaml
7.Create a deployment using the new ConfigMap, and set the max revision to be maintained as 1 in ‘spec.revisionHistoryLimit’ level.
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-deployment
spec:
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
app: service-nginx
template:
metadata:
labels:
app: service-nginx
spec:
containers:
- name: nginx
image: nginx:1.14
ports:
- containerPort: 80
volumeMounts:
- name: nginx
mountPath: "/config"
readOnly: true
volumes:
- name: nginx
configMap:
name: demo2-config
$ kubectl apply -f deployment.yaml
8.List the versions of ccm using
$kubectl get ccm
NAME AGE
demo-config-ifoiu 16m
demo-config-sg1cl 19m
demo2-config-4c897 52s
$ kubectl get replicaset
NAME DESIRED CURRENT READY AGE
demo-deployment-57d8c679b7 1 1 1 109s
9.Get new ConfigMap demo2-config as yaml. In annotation level deployment reference will be available
$ kubectl get cm demo2-config -o yaml
apiVersion: v1
data:
names: |
paul
peter
kind: ConfigMap
metadata:
annotations:
currentCustomConfigMapVersion: 21iu3
customConfigMap-name: demo2-config-21iu3
deployments: demo-deployment
updateMethod: ignoreWhenShared
creationTimestamp: "2022-02-25T08:33:29Z"
name: demo2-config
namespace: default
resourceVersion: "59171"
uid: 371d2f53-8d8a-4c9b-999f-21482502655c
10.Edit the new ConfigMap using $ kubectl edit cm demo2-config
11.Check for replicaset
$ kubectl get replicaset
NAME DESIRED CURRENT READY AGE
demo-deployment-57d8c679b7 0 0 0 4m19s
demo-deployment-5b6c7b5f57 1 1 1 40s
12.Wait for 15 mins. Check the older version is removed. The latest will be the second CCM and it will be retained. The first CCM version will be purged.
$ kubectl get replicaset demo-deployment-57d8c679b7 -o yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
annotations:
deployment.kubernetes.io/desired-replicas: "1"
deployment.kubernetes.io/max-replicas: "2"
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2022-02-25T08:36:08Z"
generation: 2
labels:
app: service-nginx
pod-template-hash: 57d8c679b7
name: demo-deployment-57d8c679b7
namespace: default
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: Deployment
name: demo-deployment
uid: 97589500-6569-4c61-a9c1-803769c0a864
resourceVersion: "56630"
uid: 52de3436-53a0-451c-aaf4-a36632ee1799
spec:
replicas: 0
selector:
matchLabels:
app: service-nginx
pod-template-hash: 57d8c679b7
template:
metadata:
annotations:
ccm-demo2-config: 4c897
config-sync-controller: configurator
$ kubectl get replicaset demo-deployment-5b6c7b5f57 -o yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
annotations:
deployment.kubernetes.io/desired-replicas: "1"
deployment.kubernetes.io/max-replicas: "2"
deployment.kubernetes.io/revision: "2"
creationTimestamp: "2022-02-25T08:39:47Z"
generation: 1
labels:
app: service-nginx
pod-template-hash: 5b6c7b5f57
name: demo-deployment-5b6c7b5f57
namespace: default
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: Deployment
name: demo-deployment
uid: 97589500-6569-4c61-a9c1-803769c0a864
resourceVersion: "56625"
uid: 09796e75-e414-4342-a522-cec9c05b2f41
spec:
replicas: 1
selector:
matchLabels:
app: service-nginx
pod-template-hash: 5b6c7b5f57
template:
metadata:
annotations:
ccm-demo2-config: we90z
config-sync-controller: configurator
$ kubectl get ccm
NAME AGE
demo-config-ifoiu 27m
demo-config-sg1cl 30m
demo2-config-4c897 11m
demo2-config-we90z 5m29s
$ kubectl edit cm demo2-config
configmap/demo2-config edited
$ kubectl get ccm
NAME AGE
demo-config-ifoiu 29m
demo-config-sg1cl 32m
demo2-config-21iu3 33s
demo2-config-4c897 13m
demo2-config-we90z 7m8s
$ kubectl get replicaset
NAME DESIRED CURRENT READY AGE
demo-deployment-5b6c7b5f57 0 0 0 7m35s
demo-deployment-8767c6b9b 1 1 1 60s
$ kubectl get replicaset demo-deployment-8767c6b9b -o yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
annotations:
deployment.kubernetes.io/desired-replicas: "1"
deployment.kubernetes.io/max-replicas: "2"
deployment.kubernetes.io/revision: "3"
creationTimestamp: "2022-02-25T08:46:22Z"
generation: 1
labels:
app: service-nginx
pod-template-hash: 8767c6b9b
name: demo-deployment-8767c6b9b
namespace: default
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: Deployment
name: demo-deployment
uid: 97589500-6569-4c61-a9c1-803769c0a864
resourceVersion: "59196"
uid: 6d7052e6-34be-4363-8970-e13843d914df
spec:
replicas: 1
selector:
matchLabels:
app: service-nginx
pod-template-hash: 8767c6b9b
template:
metadata:
annotations:
ccm-demo2-config: 21iu3
config-sync-controller: configurator
$ kubectl get ccm
NAME AGE
demo-config-ifoiu 41m
demo-config-sg1cl 44m
demo2-config-21iu3 12m
demo2-config-we90z 19m
Expected behavior
In step 5 : If a ConfigMap is not used in any deployment we must retain minimum 1 revision ie., latest revision
Activity
gopaddle-io commentedon Feb 28, 2022
Please send pull requests to SODACODE-2022