-
Notifications
You must be signed in to change notification settings - Fork 4.8k
OCPQE-32077: Add a monitortest for cluster region/zone/instance type autodl data #31305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 6 commits into
openshift:main
from
dgoodwin:autodl-region-instance-types
Jun 25, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ebc142
Add a monitortest for cluster region/zone/instance type autodl data
dgoodwin 57eb894
Remove redundant json file
dgoodwin efc8c34
Merge remote-tracking branch 'up/main' into autodl-region-instance-types
dgoodwin 438b534
Simplify and use node labels for all clouds
dgoodwin 5d13840
Add zone tracking to support AWS wavelength and edge compute pools
dgoodwin 7abc599
Track suite name tested as well
dgoodwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
200 changes: 200 additions & 0 deletions
200
pkg/monitortests/testframework/clusterinstancetypes/monitortest.go
This file contains hidden or 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,200 @@ | ||
| package clusterinstancetypes | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| "time" | ||
|
|
||
| configclient "github.com/openshift/client-go/config/clientset/versioned" | ||
| "github.com/openshift/origin/pkg/dataloader" | ||
| "github.com/openshift/origin/pkg/monitor/monitorapi" | ||
| "github.com/openshift/origin/pkg/monitortestframework" | ||
| "github.com/openshift/origin/pkg/test/ginkgo/junitapi" | ||
| "github.com/sirupsen/logrus" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/rest" | ||
| ) | ||
|
|
||
| type clusterInstanceTypes struct { | ||
| adminRESTConfig *rest.Config | ||
| suiteName string | ||
| data []instanceTypeRow | ||
| } | ||
|
|
||
| type instanceTypeRow struct { | ||
| Platform string `json:"platform"` | ||
| Region string `json:"region"` | ||
| Zone string `json:"zone"` | ||
| Role string `json:"role"` | ||
| InstanceType string `json:"instance_type"` | ||
| Suite string `json:"suite"` | ||
| } | ||
|
|
||
| func NewClusterInstanceTypes(info monitortestframework.MonitorTestInitializationInfo) monitortestframework.MonitorTest { | ||
| return &clusterInstanceTypes{ | ||
| suiteName: info.SuiteName, | ||
| } | ||
| } | ||
|
|
||
| func (w *clusterInstanceTypes) PrepareCollection(ctx context.Context, adminRESTConfig *rest.Config, recorder monitorapi.RecorderWriter) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (w *clusterInstanceTypes) StartCollection(ctx context.Context, adminRESTConfig *rest.Config, recorder monitorapi.RecorderWriter) error { | ||
| w.adminRESTConfig = adminRESTConfig | ||
| return nil | ||
| } | ||
|
|
||
| func (w *clusterInstanceTypes) CollectData(ctx context.Context, storageDir string, beginning, end time.Time) (monitorapi.Intervals, []*junitapi.JUnitTestCase, error) { | ||
| logger := logrus.WithField("MonitorTest", "ClusterInstanceTypes") | ||
|
|
||
| data, err := w.collect(ctx) | ||
| if err != nil { | ||
| logger.WithError(err).Warn("failed to collect instance type data") | ||
| return nil, nil, nil | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| w.data = data | ||
| return nil, nil, nil | ||
| } | ||
|
|
||
| func (*clusterInstanceTypes) ConstructComputedIntervals(ctx context.Context, startingIntervals monitorapi.Intervals, recordedResources monitorapi.ResourcesMap, beginning, end time.Time) (monitorapi.Intervals, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (*clusterInstanceTypes) EvaluateTestsFromConstructedIntervals(ctx context.Context, finalIntervals monitorapi.Intervals) ([]*junitapi.JUnitTestCase, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (w *clusterInstanceTypes) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error { | ||
| if len(w.data) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| rows := make([]map[string]string, 0, len(w.data)) | ||
| for _, r := range w.data { | ||
| rows = append(rows, map[string]string{ | ||
| "Platform": r.Platform, | ||
| "Region": r.Region, | ||
| "Zone": r.Zone, | ||
| "Role": r.Role, | ||
| "InstanceType": r.InstanceType, | ||
| "Suite": r.Suite, | ||
| }) | ||
| } | ||
|
|
||
| dataFile := dataloader.DataFile{ | ||
| TableName: "cluster_instance_types", | ||
| Schema: map[string]dataloader.DataType{ | ||
| "Platform": dataloader.DataTypeString, | ||
| "Region": dataloader.DataTypeString, | ||
| "Zone": dataloader.DataTypeString, | ||
| "Role": dataloader.DataTypeString, | ||
| "InstanceType": dataloader.DataTypeString, | ||
| "Suite": dataloader.DataTypeString, | ||
| }, | ||
| Rows: rows, | ||
| } | ||
|
|
||
| fileName := filepath.Join(storageDir, fmt.Sprintf("cluster-instance-types%s-%s", timeSuffix, dataloader.AutoDataLoaderSuffix)) | ||
| if err := dataloader.WriteDataFile(fileName, dataFile); err != nil { | ||
| return fmt.Errorf("failed to write instance types autodl: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (*clusterInstanceTypes) Cleanup(ctx context.Context) error { | ||
| return nil | ||
| } | ||
|
|
||
| func (w *clusterInstanceTypes) collect(ctx context.Context) ([]instanceTypeRow, error) { | ||
| configClient, err := configclient.NewForConfig(w.adminRESTConfig) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create config client: %w", err) | ||
| } | ||
|
|
||
| infra, err := configClient.ConfigV1().Infrastructures().Get(ctx, "cluster", metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get infrastructure: %w", err) | ||
| } | ||
|
|
||
| if infra.Status.PlatformStatus == nil { | ||
| logrus.Info("skipping instance type collection: platform status not set") | ||
| return nil, nil | ||
| } | ||
|
|
||
| platform := strings.ToLower(string(infra.Status.PlatformStatus.Type)) | ||
| if platform != "aws" && platform != "azure" && platform != "gcp" { | ||
| logrus.WithField("platform", platform).Info("skipping instance type collection for unsupported platform") | ||
| return nil, nil | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| kubeClient, err := kubernetes.NewForConfig(w.adminRESTConfig) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create kube client: %w", err) | ||
| } | ||
|
|
||
| nodes, err := kubeClient.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to list nodes: %w", err) | ||
| } | ||
|
|
||
| return buildRows(platform, w.suiteName, nodes.Items), nil | ||
| } | ||
|
|
||
| func buildRows(platform, suite string, nodes []corev1.Node) []instanceTypeRow { | ||
| seen := map[string]bool{} | ||
| var result []instanceTypeRow | ||
|
|
||
| for i := range nodes { | ||
| node := &nodes[i] | ||
| labels := node.Labels | ||
|
|
||
| instanceType := labels["node.kubernetes.io/instance-type"] | ||
| if instanceType == "" { | ||
| continue | ||
| } | ||
|
|
||
| region := labels["topology.kubernetes.io/region"] | ||
| zone := labels["topology.kubernetes.io/zone"] | ||
| role := nodeRole(labels) | ||
|
|
||
| key := role + "/" + instanceType + "/" + zone | ||
| if seen[key] { | ||
| continue | ||
| } | ||
| seen[key] = true | ||
| result = append(result, instanceTypeRow{ | ||
| Platform: platform, | ||
| Region: region, | ||
| Zone: zone, | ||
| Role: role, | ||
| InstanceType: instanceType, | ||
| Suite: suite, | ||
| }) | ||
| } | ||
|
|
||
| sort.Slice(result, func(i, j int) bool { | ||
| if result[i].Role != result[j].Role { | ||
| return result[i].Role < result[j].Role | ||
| } | ||
| return result[i].InstanceType < result[j].InstanceType | ||
| }) | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func nodeRole(labels map[string]string) string { | ||
| if _, ok := labels["node-role.kubernetes.io/master"]; ok { | ||
| return "control-plane" | ||
| } | ||
| if _, ok := labels["node-role.kubernetes.io/control-plane"]; ok { | ||
| return "control-plane" | ||
| } | ||
| return "worker" | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On AWS, we also support local and wavelength zones via edge compute pool.
Let's also collect zone details (for AWS only?). We can get it by inspecting node label
topology.kubernetes.io/zone, for example, in this run:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not reflected in the region? Are these zones meaningful consistent names for customers vs those that jump around with different names per account? Will all masters/workers be in the same zone in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, not at all, for example, region
us-west-2only reflects regular AZs (e.g.us-west-2a,us-west-2b). Local/Wavelength zones are special AZs that require additional day-0 configuration via edge compute pool (see EP); thus, dedicated jobs:AFAIK, local and wavelength zones are not subjected to logical zone mappings between accounts. These zones are limited and point to deterministic physical locations (local zones and wavelength zones). Besides, logical mapping is only applicable to older regions according to AWS docs and accounts created before Nov 2025.
oh, no. Local and Wavelength zones only apply to worker nodes. AFAIK, the 2 jobs above will find all available local/wavelength zones and put
1worker replica in each. For example, this job defines 20 workers for 20 local zones.