Skip to content

Commit

Permalink
chore(CI): filter kubectl error msgs (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored Feb 23, 2024
1 parent 628baf0 commit 0a2d505
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/integration/deploy_service/deploy_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDeployService(t *testing.T) {
k8sOpts := k8s.KubectlOptions{}
listServices, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "svc", "terraform-example", "-o", "json")
assert.NoError(err)
kubeService := utils.ParseJSONResult(t, listServices)
kubeService := testutils.ParseKubectlJSONResult(t, listServices)
serviceIp := kubeService.Get("status.loadBalancer.ingress").Array()[0].Get("ip")
serviceUrl := fmt.Sprintf("http://%s:8080", serviceIp)

Expand Down
5 changes: 2 additions & 3 deletions test/integration/simple_zonal/simple_zonal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/golden"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/stretchr/testify/assert"
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
Expand Down Expand Up @@ -78,11 +77,11 @@ func TestSimpleZonal(t *testing.T) {
k8sOpts := k8s.KubectlOptions{}
configNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "config-management-system", "-o", "json")
assert.NoError(err)
configkubeNS := utils.ParseJSONResult(t, configNameSpace)
configkubeNS := testutils.ParseKubectlJSONResult(t, configNameSpace)
assert.Contains(configkubeNS.Get("metadata.name").String(), "config-management-system", "Namespace is Functional")
gateKeeperNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "gatekeeper-system", "-o", "json")
assert.NoError(err)
gateKeeperkubeNS := utils.ParseJSONResult(t, gateKeeperNameSpace)
gateKeeperkubeNS := testutils.ParseKubectlJSONResult(t, gateKeeperNameSpace)
assert.Contains(gateKeeperkubeNS.Get("metadata.name").String(), "gatekeeper-system", "Namespace is Functional")
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
"github.com/gruntwork-io/terratest/modules/k8s"
"github.com/stretchr/testify/assert"
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
Expand Down Expand Up @@ -50,11 +49,11 @@ func TestSimpleZonalWithASM(t *testing.T) {
k8sOpts := k8s.KubectlOptions{}
listNameSpace, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "ns", "istio-system", "-o", "json")
assert.NoError(err)
kubeNS := utils.ParseJSONResult(t, listNameSpace)
kubeNS := testutils.ParseKubectlJSONResult(t, listNameSpace)
assert.Contains(kubeNS.Get("metadata.name").String(), "istio-system", "Namespace is Functional")
listConfigMap, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "configmap", "asm-options", "-n", "istio-system", "-o", "json")
assert.NoError(err)
kubeCM := utils.ParseJSONResult(t, listConfigMap)
kubeCM := testutils.ParseKubectlJSONResult(t, listConfigMap)
assert.Contains(kubeCM.Get("metadata.name").String(), "asm-options", "Configmap is Present")

})
Expand Down
40 changes: 40 additions & 0 deletions test/integration/testutils/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 Google LLC
//
// 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 testutils

import (
"bytes"
"testing"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
"github.com/tidwall/gjson"
)

var (
KubectlTransientErrors = []string{
"E0222 .* the server is currently unable to handle the request",
}
)

// Filter transient errors from kubectl output
func ParseKubectlJSONResult(t testing.TB, s string) gjson.Result {
bstring := []byte(s)

for _, v := range KubectlTransientErrors {
bstring = bytes.Replace(bstring, []byte(v), []byte(""), -1)
}

return utils.ParseJSONResult(t, string(bstring))
}

0 comments on commit 0a2d505

Please sign in to comment.