Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 0 additions & 267 deletions pkg/sqlcache/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,273 +738,6 @@ func (i *IntegrationSuite) TestProxyStore() {
time.Sleep(2 * time.Second)
}

/**
* Test the following:
* 1. When a management.cattle.io.cluster is processed, its memory & cpu fields are transformed
* 2. When a provisioning.cattle.io.cluster is processed, we copy in all the fields from the
* associated management.cattle.io.cluster
* 3. We can sort provisioning.cattle.io.clusters on memory & cpu even when the original values
* have different units (e.g.: ...Ki and ...Mi for memory, c and m for cpu)
*/

func (i *IntegrationSuite) TestProvisioningManagementClusterDependencies() {
ctx, cancel := context.WithCancel(i.T().Context())
defer cancel()
requireT := i.Require()
labelTest := "ProvisioningManagementClusterDependencies"

cols, ccache, svrController, sf, proxyStore, err := i.setupTest(ctx)
requireT.NoError(err)
requireT.NotNil(proxyStore)

resetMCIOCh := make(chan struct{}, 10)
resetPCIOCh := make(chan struct{}, 10)

mcioGVK := k8sschema.GroupVersionKind{
Group: "management.cattle.io",
Version: "v3",
Kind: "Cluster",
}
mcioGVR := k8sschema.GroupVersionResource{
Group: "management.cattle.io",
Version: "v3",
Resource: "clusters",
}
pcioGVK := k8sschema.GroupVersionKind{
Group: "provisioning.cattle.io",
Version: "v1",
Kind: "Cluster",
}
pcioGVR := k8sschema.GroupVersionResource{
Group: "provisioning.cattle.io",
Version: "v1",
Resource: "clusters",
}

sqlSchemaTracker := schematracker.NewSchemaTracker(ResetFunc(func(gvk k8sschema.GroupVersionKind) error {
proxyStore.Reset(gvk)
if gvk == mcioGVK {
resetMCIOCh <- struct{}{}
} else if gvk == pcioGVK {
resetPCIOCh <- struct{}{}
}
return nil
}))

onSchemasHandler := func(schemas *schema.Collection) error {
var retErr error

err := ccache.OnSchemas(schemas)
retErr = errors.Join(retErr, err)

err = sqlSchemaTracker.OnSchemas(schemas)
retErr = errors.Join(retErr, err)

return retErr
}
schemacontroller.Register(ctx,
cols,
svrController.K8s.Discovery(),
svrController.CRD.CustomResourceDefinition(),
svrController.API.APIService(),
svrController.K8s.AuthorizationV1().SelfSubjectAccessReviews(),
onSchemasHandler,
sf)

err = svrController.Start(ctx)
requireT.NoError(err)

dynamicClient, err := dynamic.NewForConfig(i.restCfg)
requireT.NoError(err)

mcioClient := dynamicClient.Resource(mcioGVR)
pcioClient := dynamicClient.Resource(pcioGVR).Namespace(defaultTestNamespace)

mcioInfo := []struct {
city string
cpu string
memory string
pods int
}{
{"kigali", "7000m", "900Ki", 17},
{"luanda", "14250m", "2610Ki", 11},
{"gaborone", "98m", "12Mi", 14},
{"gitega", "325m", "4Mi", 8},
{"bamako", "7", "1200Ki", 20},
}
for _, info := range mcioInfo {
err = createMCIO(ctx, mcioClient, mcioGVR, info.city, labelTest, info.cpu, info.memory, info.pods)
requireT.NoError(err)
}
pcioInfo := [][2]string{
{"rwanda", "kigali"},
{"angola", "luanda"},
{"botswana", "gaborone"},
{"burundi", "gitega"},
{"mali", "bamako"},
}
for _, info := range pcioInfo {
err = createPCIO(ctx, pcioClient, pcioGVR, info[0], labelTest, info[1])
requireT.NoError(err)
}

var mcioSchema *types.APISchema
var pcioSchema *types.APISchema
requireT.EventuallyWithT(func(c *assert.CollectT) {
mcioSchema = sf.Schema("management.cattle.io.cluster")
pcioSchema = sf.Schema("provisioning.cattle.io.cluster")
require.NotNil(c, mcioSchema)
require.NotNil(c, pcioSchema)
}, 15*time.Second, 500*time.Millisecond)

tests := []struct {
name string
query string
wantNames []string
}{
{
name: "sorts by name",
query: "sort=metadata.name",
wantNames: []string{
"angola",
"botswana",
"burundi",
"mali",
"rwanda",
},
},
{
name: "sorts by cluster-name",
query: "sort=status.clusterName,metadata.name",
wantNames: []string{
"mali", // bamako
"botswana", // gaborone
"burundi", // gitega
"rwanda", // kigali
"angola", // luanda
},
},
{
name: "sorts by cpu",
query: "sort=status.allocatable.cpuRaw,metadata.name",
wantNames: []string{
"botswana", // 98m
"burundi", // 325m
"mali", // 7
"rwanda", // 7000m
"angola", // 14250m
},
},
{
name: "sorts by memory",
query: "sort=status.allocatable.memoryRaw,metadata.name",
wantNames: []string{
"rwanda", // 900Ki
"mali", // 1200Ki
"angola", // 2610Ki
"burundi", // 4Mi
"botswana", // 12Mi
},
},
{
name: "sorts by pods",
query: "sort=status.allocatable.pods,metadata.name",
wantNames: []string{
"burundi", // 8
"angola", // 11
"botswana", // 14
"rwanda", // 17
"mali", // 20
},
},
{
name: "alpha-sort by raw cpu",
query: "sort=status.allocatable.cpu,metadata.name",
wantNames: []string{
"angola", // 14250m
"burundi", // 325m
"mali", // 7
"rwanda", // 7000m
"botswana", // 98m
},
},
{
name: "alpha-sort by raw memory",
query: "sort=status.allocatable.memory,metadata.name",
wantNames: []string{
"mali", // 1200Ki
"botswana", // 12Mi
"angola", // 2610Ki
"burundi", // 4Mi
"rwanda", // 900Ki
},
},
{
name: "filter on original cpu",
query: "filter=status.allocatable.cpu=7000m",
wantNames: []string{
"rwanda", // 7000m
},
},
{
name: "filter on processed cpu",
query: "filter=status.allocatable.cpuRaw=14.25",
wantNames: []string{
"angola", // 14250m
},
},
{
name: "filter on original memory",
query: "filter=status.allocatable.memory=12Mi",
wantNames: []string{
"botswana",
},
},
{
name: "filter on processed memory",
query: "filter=status.allocatable.memoryRaw=4194304",
wantNames: []string{
"burundi",
},
},
{
name: "filter on pods",
query: "filter=status.allocatable.pods=20",
wantNames: []string{
"mali",
},
},
}

err = waitForObjectsBySchema(ctx, proxyStore, mcioSchema, labelTest, len(mcioInfo))
requireT.NoError(err)
err = waitForObjectsBySchema(ctx, proxyStore, pcioSchema, labelTest, len(pcioInfo))
requireT.NoError(err)
partitions := []partition.Partition{defaultPartition}
for _, test := range tests {
test := test
i.Run(test.name, func() {
q := getFilteredQuery(test.query, labelTest)
req, err := http.NewRequest("GET", "http://localhost:8080?"+q, nil)
requireT.NoError(err)
apiOp := &types.APIRequest{
Request: req,
}

got, total, _, continueToken, err := proxyStore.ListByPartitions(apiOp, pcioSchema, partitions)
if err != nil {
i.Assert().NoError(err)
return
}
i.Assert().Equal(len(test.wantNames), total)
i.Assert().Equal("", continueToken)
i.Assert().Len(got.Items, len(test.wantNames))
gotNames := stringsFromULIst(got)
i.Assert().Equal(test.wantNames, gotNames)
})
}
}

func (i *IntegrationSuite) TestNamespaceProjectDependencies() {
ctx, cancel := context.WithCancel(i.T().Context())
defer cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ metadata:
name: bamako
status:
allocatable:
cpu: "700m"
cpu: "7"
memory: "1200Ki"
pods: "20"
conditions:
Expand Down
82 changes: 76 additions & 6 deletions tests/integration/testdata/sorting/clusters.test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---
# Test the following:
# 1. When a management.cattle.io.cluster is processed, its memory & cpu fields are transformed
# 2. When a provisioning.cattle.io.cluster is processed, we copy in all the fields from the
# associated management.cattle.io.cluster
# 3. We can sort provisioning.cattle.io.clusters on memory & cpu even when the original values
# have different units (e.g.: ...Ki and ...Mi for memory, c and m for cpu)

schemaID: provisioning.cattle.io.clusters
tests:
- query: sort=metadata.name
Expand All @@ -7,10 +15,72 @@ tests:
- default/burundi
- default/mali
- default/rwanda
- query: sort=status.clusterName,metadata.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious to know why this needed to be removed since this PR doesn't contain any code changes. Was this flaky on your side?

# Sort by CPU
- query: sort=status.allocatable.cpuRaw,metadata.name
expected:
- default/mali # bamako
- default/botswana # gaborone
- default/burundi # gitega
- default/rwanda # kigali
- default/angola # luanda
- default/botswana # 98m
- default/burundi # 325m
- default/mali # 7
- default/rwanda # 7000m
- default/angola # 14250m

# Sort by Memory
- query: sort=status.allocatable.memoryRaw,metadata.name
expected:
- default/rwanda # 900Ki
- default/mali # 1200Ki
- default/angola # 2610Ki
- default/burundi # 4Mi
- default/botswana # 12Mi

# Sort by pod count
- query: sort=status.allocatable.pods,metadata.name
expected:
- default/burundi # 8
- default/angola # 11
- default/botswana # 14
- default/rwanda # 17
- default/mali # 20

# Alphabetical sort by raw cpu
- query: sort=status.allocatable.cpu,metadata.name
expected:
- default/angola # 14250m
- default/burundi # 325m
- default/mali # 7
- default/rwanda # 7000m
- default/botswana # 98m

# Alphabetical sort by raw memory
- query: sort=status.allocatable.memory,metadata.name
expected:
- default/mali # 1200Ki
- default/botswana # 12Mi
- default/angola # 2610Ki
- default/burundi # 4Mi
- default/rwanda # 900Ki

# filter on original cpu
- query: filter=status.allocatable.cpu=7000m
expected:
- default/rwanda # 7000m

# filter on processed cpu
- query: filter=status.allocatable.cpuRaw=14.25
expected:
- default/angola # 14250m

# filter on original memory
- query: filter=status.allocatable.memory=12Mi
expected:
- default/botswana # 12Mi

# filter on processed memory
- query: filter=status.allocatable.memoryRaw=4194304
expected:
- default/burundi # 4Mi

# filter on pods
- query: filter=status.allocatable.pods=20
expected:
- default/mali
Comment on lines +63 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the test framework we ended up splitting sorting and filtering tests. Sorting test would test the order while filtering test would test the existence in the result. Though in both tests we allow pretty much any kind of query.

Should we split this test as well or keep it local to what we're testing 🤔