Skip to content

Commit

Permalink
Fix CRD handling for upgrades and removals (dapr#977) (dapr#1006)
Browse files Browse the repository at this point in the history
* Fix CRD handling for upgrades and removals

Signed-off-by: yaron2 <schneider.yaron@live.com>

* nolint

Signed-off-by: yaron2 <schneider.yaron@live.com>

* linter, fix crd name

Signed-off-by: yaron2 <schneider.yaron@live.com>

Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
Signed-off-by: hueifeng <695979933@qq.com>
  • Loading branch information
2 people authored and hueifeng committed Jul 14, 2022
1 parent 797534b commit dbad134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/kubernetes/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func Uninstall(namespace string, uninstallAll bool, timeout uint) error {
for _, crd := range crdsFullResources {
_, err := utils.RunCmdAndWait("kubectl", "delete", "crd", crd)
if err != nil {
return err
print.WarningStatusEvent(os.Stdout, "Failed to remove CRD %s: %s", crd, err)
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions pkg/kubernetes/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package kubernetes

import (
"fmt"
"net/http"
"os"
"time"

Expand All @@ -33,12 +34,14 @@ var crds = []string{
"components",
"configuration",
"subscription",
"resiliency",
}

var crdsFullResources = []string{
"components.dapr.io",
"configurations.dapr.io",
"subscriptions.dapr.io",
"resiliencies.dapr.io",
}

type UpgradeConfig struct {
Expand Down Expand Up @@ -135,9 +138,15 @@ func highAvailabilityEnabled(status []StatusOutput) bool {
func applyCRDs(version string) error {
for _, crd := range crds {
url := fmt.Sprintf("https://raw.githubusercontent.com/dapr/dapr/%s/charts/dapr/crds/%s.yaml", version, crd)
_, err := utils.RunCmdAndWait("kubectl", "apply", "-f", url)
if err != nil {
return err

resp, _ := http.Get(url) // nolint:gosec
if resp != nil && resp.StatusCode == 200 {
defer resp.Body.Close()

_, err := utils.RunCmdAndWait("kubectl", "apply", "-f", url)
if err != nil {
return err
}
}
}
return nil
Expand Down

0 comments on commit dbad134

Please sign in to comment.