From 41d90d991d8f9ca2fe1415fc81a83e33ef39c82a Mon Sep 17 00:00:00 2001 From: tejal29 Date: Tue, 14 Jul 2020 15:36:43 -0700 Subject: [PATCH 1/2] wip --- pkg/diag/download/http.go | 36 -------- pkg/diag/download/http_test.go | 29 ------ pkg/diag/recommender/cluster.go | 62 +++++++++++++ pkg/diag/recommender/custom.go | 100 --------------------- pkg/diag/recommender/custom_test.go | 134 ---------------------------- pkg/diag/recommender/gke.go | 61 +++++++++++++ pkg/diag/recommender/minikube.go | 64 +++++++++++++ pkg/diag/validator/pod.go | 7 +- pkg/diag/validator/recommender.go | 13 +++ pkg/skaffold/deploy/status_check.go | 2 +- pkg/skaffold/event/util.go | 4 +- 11 files changed, 205 insertions(+), 307 deletions(-) delete mode 100644 pkg/diag/download/http.go delete mode 100644 pkg/diag/download/http_test.go create mode 100644 pkg/diag/recommender/cluster.go delete mode 100644 pkg/diag/recommender/custom.go delete mode 100644 pkg/diag/recommender/custom_test.go create mode 100644 pkg/diag/recommender/gke.go create mode 100644 pkg/diag/recommender/minikube.go diff --git a/pkg/diag/download/http.go b/pkg/diag/download/http.go deleted file mode 100644 index b2ebbe8c905..00000000000 --- a/pkg/diag/download/http.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2020 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package download - -import ( - "fmt" - "io/ioutil" - "net/http" -) - -// HTTPDownload reads the file at given url and return the read bytes. -func HTTPDownload(url string) ([]byte, error) { - resp, err := http.Get(url) - if err != nil { - return nil, fmt.Errorf("downloading the http url %w", err) - } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("http %d, error %q", resp.StatusCode, resp.Status) - } - return ioutil.ReadAll(resp.Body) -} diff --git a/pkg/diag/download/http_test.go b/pkg/diag/download/http_test.go deleted file mode 100644 index a8139730829..00000000000 --- a/pkg/diag/download/http_test.go +++ /dev/null @@ -1,29 +0,0 @@ -/* -Copyright 2020 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package download - -import ( - "testing" - - "github.com/GoogleContainerTools/skaffold/testutil" -) - -func TestHTTPDownload(t *testing.T) { - v, err := HTTPDownload("https://storage.googleapis.com/skaffold/releases/v1.0.0/VERSION") - testutil.CheckError(t, false, err) - testutil.CheckDeepEqual(t, "v1.0.0\n", string(v)) -} diff --git a/pkg/diag/recommender/cluster.go b/pkg/diag/recommender/cluster.go new file mode 100644 index 00000000000..0a34236b352 --- /dev/null +++ b/pkg/diag/recommender/cluster.go @@ -0,0 +1,62 @@ +/* +Copyright 2020 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +package recommender + +import ( + "github.com/GoogleContainerTools/skaffold/proto" +) + +type Cluster struct {} + +func (r *Cluster) Make(errCode proto.StatusCode) proto.Suggestion { + switch errCode { + case proto.StatusCode_STATUSCHECK_NODE_MEMORY_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_MEMORY_PRESSURE, + Action: "Try checking container logs", + } + case proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, + Action: "Try checking container config `readinessProbe`", + } + case proto.StatusCode_STATUSCHECK_NODE_NETWORK_UNAVAILABLE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NETWORK_UNAVAILABLE, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_PID_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_PID_PRESSURE, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_NOT_READY: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NOT_READY, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_UNSCHEDULABLE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_UNSCHEDULABLE, + Action: "Try checking container config `image`", + } + default: + return NilSuggestion + } +} + diff --git a/pkg/diag/recommender/custom.go b/pkg/diag/recommender/custom.go deleted file mode 100644 index cba4c8181b0..00000000000 --- a/pkg/diag/recommender/custom.go +++ /dev/null @@ -1,100 +0,0 @@ -/* -Copyright 2020 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package recommender - -import ( - "encoding/json" - "strings" - - "github.com/GoogleContainerTools/skaffold/pkg/diag/download" - "github.com/GoogleContainerTools/skaffold/proto" -) - -var ( - // testing - downloadRules = download.HTTPDownload -) - -const ( - DiagDefaultRules = "https://storage.googleapis.com/skaffold/diag/customRules/v1/rules.json" -) - -type Custom struct { - RulesPath string - rules []Rule - deployContext map[string]string -} - -// NewCustom returns a custom recommender from rules file or return error -func NewCustom(path string, deployContext map[string]string) (Custom, error) { - rules, err := loadRules(path) - if err != nil { - return Custom{}, err - } - return Custom{ - RulesPath: path, - rules: rules, - deployContext: deployContext, - }, nil -} - -func (r Custom) Make(errCode proto.StatusCode) proto.Suggestion { - for _, rule := range r.rules { - if rule.Matches(errCode, r.deployContext) { - return proto.Suggestion{ - SuggestionCode: rule.SuggestionCode, - Action: rule.Suggestion, - } - } - } - return NilSuggestion -} - -func loadRules(path string) ([]Rule, error) { - var ruleConfig RulesConfigV1 - bytes, err := downloadRules(path) - if err != nil { - return nil, err - } - err = json.Unmarshal(bytes, &ruleConfig) - return ruleConfig.Rules, err -} - -type RulesConfigV1 struct { - Rules []Rule `json:"rules"` -} - -type Rule struct { - ErrCode proto.StatusCode `json:"errorCode"` - SuggestionCode proto.SuggestionCode `json:"suggestionCode"` - Suggestion string `json:"suggestion"` - ContextPrefixMatches map[string]string `json:"contextPrefixMatches"` -} - -func (r Rule) Matches(errCode proto.StatusCode, deployContext map[string]string) bool { - if r.ErrCode != errCode { - return false - } - for k, prefix := range r.ContextPrefixMatches { - if value, ok := deployContext[k]; ok { - if !strings.HasPrefix(value, prefix) { - return false - } - } - } - return true -} diff --git a/pkg/diag/recommender/custom_test.go b/pkg/diag/recommender/custom_test.go deleted file mode 100644 index a44269a5767..00000000000 --- a/pkg/diag/recommender/custom_test.go +++ /dev/null @@ -1,134 +0,0 @@ -/* -Copyright 2019 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package recommender - -import ( - "testing" - - "github.com/GoogleContainerTools/skaffold/proto" - "github.com/GoogleContainerTools/skaffold/testutil" -) - -func TestCustomRecos(t *testing.T) { - tests := []struct { - description string - deployContext map[string]string - rulesJSON []byte - errCode proto.StatusCode - expected proto.Suggestion - }{ - { - description: "test simple rule without any context prefixes", - rulesJSON: []byte(`{ -"rules": [{ - "errorCode": 401, - "suggestionCode": 401, - "suggestion": "Try deleting stale pods", - "contextPrefixMatches": {} -}] -}`), - errCode: proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE, - expected: proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try deleting stale pods", - }, - }, - { - description: "test simple rule with a context prefixes", - rulesJSON: []byte(`{ - "rules": [{ - "errorCode": 401, - "suggestionCode": 401, - "suggestion": "Try running minikube status", - "contextPrefixMatches": { - "clusterName": "minikube" - } - }, - { - "errorCode": 401, - "suggestionCode": 401, - "suggestion": "Try running gcloud", - "contextPrefixMatches": { - "clusterName": "gke_" - } - } - ] -}`), - errCode: proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE, - deployContext: map[string]string{ - "clusterName": "gke_test", - }, - expected: proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try running gcloud", - }, - }, - } - - for _, test := range tests { - testutil.Run(t, test.description, func(t *testutil.T) { - mDownload := func(_ string) ([]byte, error) { - return test.rulesJSON, nil - } - t.Override(&downloadRules, mDownload) - - r, err := NewCustom("testHtpp.json", test.deployContext) - t.CheckNoError(err) - t.CheckDeepEqual(test.expected, r.Make(test.errCode)) - }) - } -} - -func TestCustomRecosInt(t *testing.T) { - tests := []struct { - description string - deployContext map[string]string - errCode proto.StatusCode - expected proto.Suggestion - }{ - { - description: "test simple rule without any context prefixes", - errCode: proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE, - deployContext: map[string]string{ - "clusterName": "minikube", - }, - expected: proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try running minikube status", - }, - }, - { - description: "test simple rule with a context prefixes", - errCode: proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE, - deployContext: map[string]string{ - "clusterName": "gke_test", - }, - expected: proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try running gcloud", - }, - }, - } - - for _, test := range tests { - testutil.Run(t, test.description, func(t *testutil.T) { - r, err := NewCustom(DiagDefaultRules, test.deployContext) - t.CheckNoError(err) - t.CheckDeepEqual(test.expected, r.Make(test.errCode)) - }) - } -} diff --git a/pkg/diag/recommender/gke.go b/pkg/diag/recommender/gke.go new file mode 100644 index 00000000000..a01d3aa7783 --- /dev/null +++ b/pkg/diag/recommender/gke.go @@ -0,0 +1,61 @@ +/* +Copyright 2020 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +package recommender + +import ( + "github.com/GoogleContainerTools/skaffold/proto" +) + +type GKE struct {} + +func (r *GKE) Make(errCode proto.StatusCode) proto.Suggestion { + switch errCode { + case proto.StatusCode_STATUSCHECK_NODE_MEMORY_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_MEMORY_PRESSURE, + Action: "Try checking container logs", + } + case proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, + Action: "Try checking container config `readinessProbe`", + } + case proto.StatusCode_STATUSCHECK_NODE_NETWORK_UNAVAILABLE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NETWORK_UNAVAILABLE, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_PID_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_PID_PRESSURE, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_NOT_READY: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NOT_READY, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_UNSCHEDULABLE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_UNSCHEDULABLE, + Action: "Try checking container config `image`", + } + default: + return NilSuggestion + } +} diff --git a/pkg/diag/recommender/minikube.go b/pkg/diag/recommender/minikube.go new file mode 100644 index 00000000000..50fb745ca0b --- /dev/null +++ b/pkg/diag/recommender/minikube.go @@ -0,0 +1,64 @@ +/* +Copyright 2020 The Skaffold Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +package recommender + +import ( + "github.com/GoogleContainerTools/skaffold/proto" +) + +type Minikube struct {} + +func (r *Minikube) Make(errCode proto.StatusCode) proto.Suggestion { + switch errCode { + case proto.StatusCode_STATUSCHECK_NODE_MEMORY_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_MEMORY_PRESSURE, + Action: "Try checking container logs", + } + case proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, + Action: "Try checking container config `readinessProbe`", + } + case proto.StatusCode_STATUSCHECK_NODE_NETWORK_UNAVAILABLE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NETWORK_UNAVAILABLE, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_PID_PRESSURE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_PID_PRESSURE, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_NOT_READY: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NOT_READY, + Action: "Try checking container config `image`", + } + case proto.StatusCode_STATUSCHECK_NODE_UNSCHEDULABLE: + return proto.Suggestion{ + SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_UNSCHEDULABLE, + Action: "Try checking container config `image`", + } + default: + return NilSuggestion + } +} + + + diff --git a/pkg/diag/validator/pod.go b/pkg/diag/validator/pod.go index 5e49e69452b..79a2bb2a2cf 100644 --- a/pkg/diag/validator/pod.go +++ b/pkg/diag/validator/pod.go @@ -74,11 +74,8 @@ type PodValidator struct { } // NewPodValidator initializes a PodValidator -func NewPodValidator(k kubernetes.Interface, deployContext map[string]string) *PodValidator { - rs := []Recommender{recommender.ContainerError{}} - if r, err := recommender.NewCustom(recommender.DiagDefaultRules, deployContext); err == nil { - rs = append(rs, r) - } +func NewPodValidator(k kubernetes.Interface, clusterType proto.ClusterType) *PodValidator { + rs := []Recommender{recommender.ContainerError{}, NewInfraError(clusterType)} return &PodValidator{k: k, recos: rs} } diff --git a/pkg/diag/validator/recommender.go b/pkg/diag/validator/recommender.go index 0ffca5a14f3..e2ffd08d553 100644 --- a/pkg/diag/validator/recommender.go +++ b/pkg/diag/validator/recommender.go @@ -17,6 +17,7 @@ limitations under the License. package validator import ( + "github.com/GoogleContainerTools/skaffold/pkg/diag/recommender" "github.com/GoogleContainerTools/skaffold/proto" ) @@ -25,3 +26,15 @@ type Recommender interface { // Makes one or more recommendations for the ErrorCode in err and updates the err with suggestions Make(errCode proto.StatusCode) proto.Suggestion } + + +func NewInfraError(clusterType proto.ClusterType) Recommender { + switch clusterType { + case proto.ClusterType_MINIKUBE : + return &recommender.Minikube{} + case proto.ClusterType_GKE : + return &recommender.GKE{} + default: + return &recommender.Cluster{} + } +} \ No newline at end of file diff --git a/pkg/skaffold/deploy/status_check.go b/pkg/skaffold/deploy/status_check.go index 166efccd3a0..e316f9ab984 100644 --- a/pkg/skaffold/deploy/status_check.go +++ b/pkg/skaffold/deploy/status_check.go @@ -135,7 +135,7 @@ func getDeployments(client kubernetes.Interface, ns string, l *DefaultLabeller, } pd := diag.New([]string{d.Namespace}). WithLabel(RunIDLabel, l.Labels()[RunIDLabel]). - WithValidators([]validator.Validator{validator.NewPodValidator(client, deployContext)}) + WithValidators([]validator.Validator{validator.NewPodValidator(client, event.GetClusterType(runCtx.KubeContext))}) for k, v := range d.Spec.Template.Labels { pd = pd.WithLabel(k, v) diff --git a/pkg/skaffold/event/util.go b/pkg/skaffold/event/util.go index 9ce048cabfb..53e916621ad 100644 --- a/pkg/skaffold/event/util.go +++ b/pkg/skaffold/event/util.go @@ -94,7 +94,7 @@ func getDeploy(d latest.DeployConfig, c string) *proto.DeployMetadata { return &proto.DeployMetadata{ Deployers: deployers, - Cluster: getClusterType(c), + Cluster: GetClusterType(c), } } @@ -106,7 +106,7 @@ func updateOrAddKey(m map[proto.BuilderType]int, k proto.BuilderType) { m[k] = 1 } -func getClusterType(c string) proto.ClusterType { +func GetClusterType(c string) proto.ClusterType { switch { case strings.Contains(c, "minikube"): return proto.ClusterType_MINIKUBE From 40c172a139e89048408cb2d5063a591dd5708b85 Mon Sep 17 00:00:00 2001 From: tejal29 Date: Tue, 18 Aug 2020 23:57:23 -0700 Subject: [PATCH 2/2] remove remote rules --- pkg/diag/recommender/cluster.go | 62 ---------------------------- pkg/diag/recommender/gke.go | 61 --------------------------- pkg/diag/recommender/minikube.go | 64 ----------------------------- pkg/diag/validator/pod.go | 4 +- pkg/diag/validator/recommender.go | 13 ------ pkg/skaffold/deploy/status_check.go | 10 +---- pkg/skaffold/event/util.go | 4 +- 7 files changed, 5 insertions(+), 213 deletions(-) delete mode 100644 pkg/diag/recommender/cluster.go delete mode 100644 pkg/diag/recommender/gke.go delete mode 100644 pkg/diag/recommender/minikube.go diff --git a/pkg/diag/recommender/cluster.go b/pkg/diag/recommender/cluster.go deleted file mode 100644 index 0a34236b352..00000000000 --- a/pkg/diag/recommender/cluster.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2020 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - - -package recommender - -import ( - "github.com/GoogleContainerTools/skaffold/proto" -) - -type Cluster struct {} - -func (r *Cluster) Make(errCode proto.StatusCode) proto.Suggestion { - switch errCode { - case proto.StatusCode_STATUSCHECK_NODE_MEMORY_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_MEMORY_PRESSURE, - Action: "Try checking container logs", - } - case proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try checking container config `readinessProbe`", - } - case proto.StatusCode_STATUSCHECK_NODE_NETWORK_UNAVAILABLE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NETWORK_UNAVAILABLE, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_PID_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_PID_PRESSURE, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_NOT_READY: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NOT_READY, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_UNSCHEDULABLE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_UNSCHEDULABLE, - Action: "Try checking container config `image`", - } - default: - return NilSuggestion - } -} - diff --git a/pkg/diag/recommender/gke.go b/pkg/diag/recommender/gke.go deleted file mode 100644 index a01d3aa7783..00000000000 --- a/pkg/diag/recommender/gke.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2020 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - - -package recommender - -import ( - "github.com/GoogleContainerTools/skaffold/proto" -) - -type GKE struct {} - -func (r *GKE) Make(errCode proto.StatusCode) proto.Suggestion { - switch errCode { - case proto.StatusCode_STATUSCHECK_NODE_MEMORY_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_MEMORY_PRESSURE, - Action: "Try checking container logs", - } - case proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try checking container config `readinessProbe`", - } - case proto.StatusCode_STATUSCHECK_NODE_NETWORK_UNAVAILABLE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NETWORK_UNAVAILABLE, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_PID_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_PID_PRESSURE, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_NOT_READY: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NOT_READY, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_UNSCHEDULABLE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_UNSCHEDULABLE, - Action: "Try checking container config `image`", - } - default: - return NilSuggestion - } -} diff --git a/pkg/diag/recommender/minikube.go b/pkg/diag/recommender/minikube.go deleted file mode 100644 index 50fb745ca0b..00000000000 --- a/pkg/diag/recommender/minikube.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2020 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - - -package recommender - -import ( - "github.com/GoogleContainerTools/skaffold/proto" -) - -type Minikube struct {} - -func (r *Minikube) Make(errCode proto.StatusCode) proto.Suggestion { - switch errCode { - case proto.StatusCode_STATUSCHECK_NODE_MEMORY_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_MEMORY_PRESSURE, - Action: "Try checking container logs", - } - case proto.StatusCode_STATUSCHECK_NODE_DISK_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_DISK_PRESSURE, - Action: "Try checking container config `readinessProbe`", - } - case proto.StatusCode_STATUSCHECK_NODE_NETWORK_UNAVAILABLE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NETWORK_UNAVAILABLE, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_PID_PRESSURE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_PID_PRESSURE, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_NOT_READY: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_NOT_READY, - Action: "Try checking container config `image`", - } - case proto.StatusCode_STATUSCHECK_NODE_UNSCHEDULABLE: - return proto.Suggestion{ - SuggestionCode: proto.SuggestionCode_ADDRESS_NODE_UNSCHEDULABLE, - Action: "Try checking container config `image`", - } - default: - return NilSuggestion - } -} - - - diff --git a/pkg/diag/validator/pod.go b/pkg/diag/validator/pod.go index 79a2bb2a2cf..ed73b3570ff 100644 --- a/pkg/diag/validator/pod.go +++ b/pkg/diag/validator/pod.go @@ -74,8 +74,8 @@ type PodValidator struct { } // NewPodValidator initializes a PodValidator -func NewPodValidator(k kubernetes.Interface, clusterType proto.ClusterType) *PodValidator { - rs := []Recommender{recommender.ContainerError{}, NewInfraError(clusterType)} +func NewPodValidator(k kubernetes.Interface) *PodValidator { + rs := []Recommender{recommender.ContainerError{}} return &PodValidator{k: k, recos: rs} } diff --git a/pkg/diag/validator/recommender.go b/pkg/diag/validator/recommender.go index e2ffd08d553..0ffca5a14f3 100644 --- a/pkg/diag/validator/recommender.go +++ b/pkg/diag/validator/recommender.go @@ -17,7 +17,6 @@ limitations under the License. package validator import ( - "github.com/GoogleContainerTools/skaffold/pkg/diag/recommender" "github.com/GoogleContainerTools/skaffold/proto" ) @@ -26,15 +25,3 @@ type Recommender interface { // Makes one or more recommendations for the ErrorCode in err and updates the err with suggestions Make(errCode proto.StatusCode) proto.Suggestion } - - -func NewInfraError(clusterType proto.ClusterType) Recommender { - switch clusterType { - case proto.ClusterType_MINIKUBE : - return &recommender.Minikube{} - case proto.ClusterType_GKE : - return &recommender.GKE{} - default: - return &recommender.Cluster{} - } -} \ No newline at end of file diff --git a/pkg/skaffold/deploy/status_check.go b/pkg/skaffold/deploy/status_check.go index e316f9ab984..dd7c95bbf3b 100644 --- a/pkg/skaffold/deploy/status_check.go +++ b/pkg/skaffold/deploy/status_check.go @@ -53,10 +53,6 @@ const ( kubernetesMaxDeadline = 600 ) -var ( - deployContext map[string]string -) - type counter struct { total int pending int32 @@ -76,10 +72,6 @@ func statusCheck(ctx context.Context, defaultLabeller *DefaultLabeller, runCtx * return proto.StatusCode_STATUSCHECK_KUBECTL_CLIENT_FETCH_ERR, fmt.Errorf("getting Kubernetes client: %w", err) } - deployContext = map[string]string{ - "clusterName": runCtx.GetKubeContext(), - } - deployments := make([]*resource.Deployment, 0) for _, n := range runCtx.GetNamespaces() { newDeployments, err := getDeployments(client, n, defaultLabeller, @@ -135,7 +127,7 @@ func getDeployments(client kubernetes.Interface, ns string, l *DefaultLabeller, } pd := diag.New([]string{d.Namespace}). WithLabel(RunIDLabel, l.Labels()[RunIDLabel]). - WithValidators([]validator.Validator{validator.NewPodValidator(client, event.GetClusterType(runCtx.KubeContext))}) + WithValidators([]validator.Validator{validator.NewPodValidator(client)}) for k, v := range d.Spec.Template.Labels { pd = pd.WithLabel(k, v) diff --git a/pkg/skaffold/event/util.go b/pkg/skaffold/event/util.go index 53e916621ad..9ce048cabfb 100644 --- a/pkg/skaffold/event/util.go +++ b/pkg/skaffold/event/util.go @@ -94,7 +94,7 @@ func getDeploy(d latest.DeployConfig, c string) *proto.DeployMetadata { return &proto.DeployMetadata{ Deployers: deployers, - Cluster: GetClusterType(c), + Cluster: getClusterType(c), } } @@ -106,7 +106,7 @@ func updateOrAddKey(m map[proto.BuilderType]int, k proto.BuilderType) { m[k] = 1 } -func GetClusterType(c string) proto.ClusterType { +func getClusterType(c string) proto.ClusterType { switch { case strings.Contains(c, "minikube"): return proto.ClusterType_MINIKUBE