Skip to content

Commit

Permalink
Initialize backingimage and backingimagedatasource sourceType
Browse files Browse the repository at this point in the history
Fix upgrade failure from v1.1.x to master-head.
The sourceType of backingimage and backingimagedatasource in v1.1.x is
"", so initialize it in the mutating webhook.

Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit authored and innobead committed Feb 12, 2022
1 parent 256a780 commit d885794
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions webhook/resources/backingimage/mutator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package backingimage

import (
"fmt"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"

Expand Down Expand Up @@ -45,6 +47,10 @@ func mutateBackingImage(newObj runtime.Object) (admission.PatchOps, error) {

backingImage := newObj.(*longhorn.BackingImage)

if backingImage.Spec.SourceType == "" {
patchOps = append(patchOps, fmt.Sprintf(`{"op": "replace", "path": "/spec/sourceType", "value": "%s"}`, longhorn.BackingImageDataSourceTypeDownload))
}

if backingImage.Spec.Disks == nil {
patchOps = append(patchOps, `{"op": "replace", "path": "/spec/disks", "value": {}}`)
}
Expand Down
6 changes: 6 additions & 0 deletions webhook/resources/backingimagedatasource/mutator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package backingimagedatasource

import (
"fmt"

admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"

Expand Down Expand Up @@ -45,6 +47,10 @@ func mutateBackingImageDatasource(newObj runtime.Object) (admission.PatchOps, er

backingimagedatasource := newObj.(*longhorn.BackingImageDataSource)

if backingimagedatasource.Spec.SourceType == "" {
patchOps = append(patchOps, fmt.Sprintf(`{"op": "replace", "path": "/spec/sourceType", "value": "%s"}`, longhorn.BackingImageDataSourceTypeDownload))
}

if backingimagedatasource.Spec.Parameters == nil {
patchOps = append(patchOps, `{"op": "replace", "path": "/spec/parameters", "value": {}}`)
}
Expand Down

0 comments on commit d885794

Please sign in to comment.