Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: clean up orphaned thinruntime resources #3393

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions charts/thin/templates/config/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ metadata:
chart: {{ template "thin.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
ownerReferences:
{{- if .Values.owner.enabled }}
- apiVersion: {{ .Values.owner.apiVersion }}
blockOwnerDeletion: {{ .Values.owner.blockOwnerDeletion }}
controller: {{ .Values.owner.controller }}
kind: {{ .Values.owner.kind }}
name: {{ .Values.owner.name }}
uid: {{ .Values.owner.uid }}
{{- end }}
data:
runtime.json: |
{{ .Values.runtimeValue }}
18 changes: 18 additions & 0 deletions charts/thin/templates/fuseconfig/fuseconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: thin-fuse
ownerReferences:
{{- if .Values.owner.enabled }}
- apiVersion: {{ .Values.owner.apiVersion }}
blockOwnerDeletion: {{ .Values.owner.blockOwnerDeletion }}
controller: {{ .Values.owner.controller }}
kind: {{ .Values.owner.kind }}
name: {{ .Values.owner.name }}
uid: {{ .Values.owner.uid }}
{{- end }}
data:
config.json: |
{{ .Values.fuse.configValue }}
Expand All @@ -23,6 +32,15 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: thin-fuse
ownerReferences:
{{- if .Values.owner.enabled }}
- apiVersion: {{ .Values.owner.apiVersion }}
blockOwnerDeletion: {{ .Values.owner.blockOwnerDeletion }}
controller: {{ .Values.owner.controller }}
kind: {{ .Values.owner.kind }}
name: {{ .Values.owner.name }}
uid: {{ .Values.owner.uid }}
{{- end }}
type: Opaque
stringData:
config.json: |
Expand Down
26 changes: 26 additions & 0 deletions pkg/ddc/thin/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ func (t *ThinEngine) destroyMaster() (err error) {
if err != nil {
return
}
} else {
// When upgrade Fluid to v1.0.0+ from a lower version, there may be some orphaned configmaps when deleting a ThinRuntime if it's created before the upgradation.
// Detect such orphaned configmaps and clean them up.
err = t.cleanUpOrphanedResources()
if err != nil {
t.Log.Info("WARNING: failed to delete orphaned resource, some resources may not be cleaned up in the cluster", "err", err)
err = nil
}
}

return
}

Expand Down Expand Up @@ -251,3 +260,20 @@ func (t *ThinEngine) cleanAll() (err error) {

return nil
}

func (t *ThinEngine) cleanUpOrphanedResources() (err error) {
orphanedConfigMapName := fmt.Sprintf("%s-runtimeset", t.name)
cm, err := kubeclient.GetConfigmapByName(t.Client, orphanedConfigMapName, t.namespace)
if err != nil {
return err
}

if cm != nil {
if err = kubeclient.DeleteConfigMap(t.Client, orphanedConfigMapName, t.namespace); err != nil && utils.IgnoreNotFound(err) != nil {
return err
}
t.Log.Info("Found orphaned configmap, successfully deleted it", "configmap", orphanedConfigMapName)
}

return nil
}
15 changes: 15 additions & 0 deletions pkg/ddc/thin/shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,19 @@ func TestThinEngine_destroyMaster(t *testing.T) {
}
}

orphanedCm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: "fluid",
Name: "test-runtimeset",
},
}
client := fake.NewFakeClientWithScheme(testScheme, orphanedCm)

engine := ThinEngine{
name: "test",
namespace: "fluid",
Log: fake.NullLogger(),
Client: client,
runtime: &datav1alpha1.ThinRuntime{
Spec: datav1alpha1.ThinRuntimeSpec{
Fuse: datav1alpha1.ThinFuseSpec{},
Expand Down Expand Up @@ -270,6 +279,12 @@ func TestThinEngine_destroyMaster(t *testing.T) {
t.Errorf("fail to exec check helm release: %v", err)
}

if cm, err := kubeclient.GetConfigmapByName(engine.Client, orphanedCm.Name, orphanedCm.Namespace); err != nil {
t.Errorf("fail to delete orphaned resources: %v", err)
} else if cm != nil {
t.Errorf("orphaned configmap should be cleaned up")
}

// check release error
err = gohook.Hook(helm.CheckRelease, mockExecCheckReleaseErr, nil)
if err != nil {
Expand Down