-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Add error message for unsupported k8s API version (#2156)
* 🐛 Add error message for unsupported k8s API version Fixes #2129 Signed-off-by: Christian Zunker <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: apps/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
naemspace: default | ||
labels: | ||
app: nginx | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" | ||
"go.mondoo.com/cnquery/v9/providers/k8s/connection/manifest" | ||
"go.mondoo.com/cnquery/v9/providers/k8s/connection/shared" | ||
sharedres "go.mondoo.com/cnquery/v9/providers/k8s/connection/shared/resources" | ||
) | ||
|
||
func TestManifestFile_OutdatedApi(t *testing.T) { | ||
manifestFile := "./testdata/nginx-deployment.yaml" | ||
|
||
conn, err := manifest.NewConnection(0, &inventory.Asset{ | ||
Connections: []*inventory.Config{ | ||
{ | ||
Options: map[string]string{ | ||
shared.OPTION_NAMESPACE: "default", | ||
}, | ||
}, | ||
}, | ||
}, manifest.WithManifestFile(manifestFile)) | ||
require.NoError(t, err) | ||
require.NotNil(t, conn) | ||
|
||
manifestConn := conn.(*manifest.Connection) | ||
deployment := manifestConn.ManifestParser.Objects[0] | ||
|
||
parsed, err := sharedres.GetPodSpec(deployment) | ||
require.Error(t, err) | ||
require.Nil(t, parsed) | ||
require.Equal(t, "object Deployment with version apps/v1beta1 is not supported", err.Error()) | ||
} |