Fix CRD handling for upgrades and removals (#977)

* 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>
This commit is contained in:
Yaron Schneider 2022-05-05 21:48:53 -07:00 committed by GitHub
parent 1c0c3def78
commit 436253778a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -14,10 +14,12 @@ limitations under the License.
package kubernetes package kubernetes
import ( import (
"os"
"time" "time"
helm "helm.sh/helm/v3/pkg/action" helm "helm.sh/helm/v3/pkg/action"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/utils" "github.com/dapr/cli/utils"
) )
@ -39,7 +41,7 @@ func Uninstall(namespace string, uninstallAll bool, timeout uint) error {
for _, crd := range crdsFullResources { for _, crd := range crdsFullResources {
_, err := utils.RunCmdAndWait("kubectl", "delete", "crd", crd) _, err := utils.RunCmdAndWait("kubectl", "delete", "crd", crd)
if err != nil { if err != nil {
return err print.WarningStatusEvent(os.Stdout, "Failed to remove CRD %s: %s", crd, err)
} }
} }
} }

View File

@ -15,6 +15,7 @@ package kubernetes
import ( import (
"fmt" "fmt"
"net/http"
"os" "os"
"time" "time"
@ -33,12 +34,14 @@ var crds = []string{
"components", "components",
"configuration", "configuration",
"subscription", "subscription",
"resiliency",
} }
var crdsFullResources = []string{ var crdsFullResources = []string{
"components.dapr.io", "components.dapr.io",
"configurations.dapr.io", "configurations.dapr.io",
"subscriptions.dapr.io", "subscriptions.dapr.io",
"resiliencies.dapr.io",
} }
type UpgradeConfig struct { type UpgradeConfig struct {
@ -134,11 +137,17 @@ func highAvailabilityEnabled(status []StatusOutput) bool {
func applyCRDs(version string) error { func applyCRDs(version string) error {
for _, crd := range crds { for _, crd := range crds {
url := fmt.Sprintf("https://raw.githubusercontent.com/dapr/dapr/%s/charts/dapr/crds/%s.yaml", version, crd) url := fmt.Sprintf("https://raw.githubusercontent.com/dapr/dapr/%s/charts/dapr/crds/%s.yaml", version, crd)
resp, _ := http.Get(url) // nolint:gosec
if resp != nil && resp.StatusCode == 200 {
defer resp.Body.Close()
_, err := utils.RunCmdAndWait("kubectl", "apply", "-f", url) _, err := utils.RunCmdAndWait("kubectl", "apply", "-f", url)
if err != nil { if err != nil {
return err return err
} }
} }
}
return nil return nil
} }