Skip to content

Commit 15d318a

Browse files
committed
multi asset types
1 parent 1c9487a commit 15d318a

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

test/integration/node_pool/node_pool_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func TestNodePool(t *testing.T) {
4242

4343
//cluster := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
4444
clusterResourceName := fmt.Sprintf("//container.googleapis.com/projects/%s/locations/%s/clusters/%s", projectId, location, clusterName)
45-
cluster := gkeutils.GetProjectResources(t, projectId, gkeutils.WithAssetType("container.googleapis.com/Cluster")).Get("#(name=\"" + clusterResourceName + "\").resource.data")
45+
cluster := gkeutils.GetProjectResources(t, projectId, gkeutils.WithAssetTypes([]string{"container.googleapis.com/Cluster"})).Get("#(name=\"" + clusterResourceName + "\").resource.data")
4646

4747
// Cluster
4848
assert.Contains([]string{"RUNNING", "RECONCILING"}, cluster.Get("status").String(), "Cluster is Running")
4949
assert.Equal("COS_CONTAINERD", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.imageType").String(), "has the expected image type")
50-
assert.Equal("[\n \"https://www.googleapis.com/auth/cloud-platform\"\n ]", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.oauthScopes").String(), "has the expected oauth scopes")
50+
assert.Equal("https://www.googleapis.com/auth/cloud-platform", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.oauthScopes.1").String(), "has the expected oauth scopes")
5151
assert.Equal("default", cluster.Get("autoscaling.autoprovisioningNodePoolDefaults.serviceAccount").String(), "has the expected service account")
5252
assert.Equal("OPTIMIZE_UTILIZATION", cluster.Get("autoscaling.autoscalingProfile").String(), "has the expected autoscaling profile")
5353
assert.True(cluster.Get("autoscaling.enableNodeAutoprovisioning").Bool(), "has the expected node autoprovisioning")
@@ -148,6 +148,11 @@ func TestNodePool(t *testing.T) {
148148
"effect": "PreferNoSchedule",
149149
"key": "all-pools-example",
150150
"value": "true"
151+
},
152+
{
153+
"effect": "NoSchedule",
154+
"key": "nvidia.com/gpu",
155+
"value": "present"
151156
}
152157
]`,
153158
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-02\").spec.taints").String(), "has the expected all-pools-example taint")
@@ -156,6 +161,11 @@ func TestNodePool(t *testing.T) {
156161
"effect": "PreferNoSchedule",
157162
"key": "all-pools-example",
158163
"value": "true"
164+
},
165+
{
166+
"effect": "NoSchedule",
167+
"key": "sandbox.gke.io/runtime",
168+
"value": "gvisor"
159169
}
160170
]`,
161171
clusterNodes.Get("items.#(metadata.labels.node_pool==\"pool-03\").spec.taints").String(), "has the expected all-pools-example taint")

test/integration/utils/cai.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package utils
1919

2020
import (
21+
"fmt"
22+
"strings"
2123
"testing"
2224
"time"
2325

@@ -26,23 +28,30 @@ import (
2628
)
2729

2830
type CmdCfg struct {
29-
sleep int // minutes to sleep prior to CAI retreval. default: 2
30-
assetType string // asset type to retrieve. default: all
31+
sleep int // minutes to sleep prior to CAI retreval. default: 2
32+
assetTypes []string // asset types to retrieve. empty: all
33+
args []string // arguments to pass to call
3134
}
3235

3336
type cmdOption func(*CmdCfg)
3437

3538
// newCmdConfig sets defaults and options
3639
func newCmdConfig(opts ...cmdOption) (*CmdCfg) {
3740
caiOpts := &CmdCfg{
38-
sleep: 2,
39-
assetType: "",
41+
sleep: 2,
42+
assetTypes: nil,
43+
args: nil,
4044
}
4145

4246
for _, opt := range opts {
4347
opt(caiOpts)
4448
}
4549

50+
if caiOpts.assetTypes != nil {
51+
caiOpts.args = []string{"--asset-types", strings.Join(caiOpts.assetTypes, ",")}
52+
}
53+
caiOpts.args = append(caiOpts.args, "--content-type", "resource")
54+
4655
return caiOpts
4756
}
4857

@@ -53,20 +62,21 @@ func WithSleep(sleep int) cmdOption {
5362
}
5463
}
5564

56-
// Set asset type
57-
func WithAssetType(assetType string) cmdOption {
65+
// Set asset types
66+
func WithAssetTypes(assetTypes []string) cmdOption {
5867
return func(f *CmdCfg) {
59-
f.assetType = assetType
68+
f.assetTypes = assetTypes
6069
}
6170
}
6271

6372
// GetProjectResources returns the cloud asset inventory resources for a project as a gjson.Result
6473
func GetProjectResources(t testing.TB, project string, opts ...cmdOption) gjson.Result {
6574
caiOpts := newCmdConfig(opts...)
75+
76+
// Cloud Asset Inventory offers best-effort data freshness.
77+
t.Logf("Sleeping for %d minutes before retrieving Cloud Asset Inventory...", caiOpts.sleep)
6678
time.Sleep(time.Duration(caiOpts.sleep) * time.Minute)
67-
if caiOpts.assetType != "" {
68-
return gcloud.Runf(t, "asset list --project=%s --asset-types=%s --content-type=resource", project, caiOpts.assetType)
69-
} else {
70-
return gcloud.Runf(t, "asset list --project=%s --content-type=resource", project)
71-
}
79+
80+
cmd := fmt.Sprintf("asset list --project %s", project)
81+
return gcloud.Runf(t, strings.Join(append([]string{cmd}, caiOpts.args...), " "))
7282
}

0 commit comments

Comments
 (0)