-
Notifications
You must be signed in to change notification settings - Fork 18
add blueray cluster support for saving the cluster information #63
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -163,8 +163,50 @@ func (p *PulumiMySQLRunRecorder) findPulumiStackFromClusterFQDN(ctx context.Cont | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func (p *PulumiMySQLRunRecorder) findStackFromClusterFQDN(ctx context.Context, clusterFQDN string) *PulumiResource { | ||||||
| // Check if the cluster FQDN matches the Presto DB pattern | ||||||
| if regexp.MustCompile(`.+\.ibm\.prestodb\.dev`).MatchString(clusterFQDN) { | ||||||
| return p.findPulumiStackFromClusterFQDN(ctx, clusterFQDN) | ||||||
| } | ||||||
|
|
||||||
| // Check if the cluster FQDN matches the blueray pattern | ||||||
| if regexp.MustCompile(`.+\.cloud\.ibm\.com`).MatchString(clusterFQDN) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know if we can use our internal fork?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| return p.findBluerayStackFromClusterFQDN(ctx, clusterFQDN) | ||||||
| } | ||||||
|
|
||||||
| // Log if the FQDN doesn't match any known pattern | ||||||
| log.Warn().Str("cluster_fqdn", clusterFQDN).Msg("cluster FQDN does not match any known pattern") | ||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func (p *PulumiMySQLRunRecorder) findBluerayStackFromClusterFQDN(ctx context.Context, clusterFQDN string) *PulumiResource { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you actually do not need a context.Context here |
||||||
| // Extract cluster name as the first part of the FQDN (before the first dot) | ||||||
| parts := regexp.MustCompile(`\.`).Split(clusterFQDN, 2) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you do not need to use regex because you just need to get the part before the dot.
Suggested change
|
||||||
| if len(parts) < 2 { | ||||||
| log.Error().Str("cluster_fqdn", clusterFQDN).Msg("failed to extract cluster name from Blueray FQDN") | ||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| clusterName := parts[0] | ||||||
|
|
||||||
| // Create a PulumiResource with the extracted information | ||||||
| resource := &PulumiResource{ | ||||||
| Type: PulumiResourceTypeStack, | ||||||
| Created: time.Now(), | ||||||
| } | ||||||
|
|
||||||
| // Set the outputs | ||||||
| resource.Outputs.ClusterFQDN = clusterFQDN | ||||||
| resource.Outputs.ClusterName = clusterName | ||||||
|
|
||||||
| log.Info().Str("cluster_name", clusterName).Str("cluster_fqdn", clusterFQDN). | ||||||
| Msg("extracted cluster information from Blueray FQDN") | ||||||
|
|
||||||
| return resource | ||||||
| } | ||||||
|
|
||||||
| func (p *PulumiMySQLRunRecorder) Start(ctx context.Context, s *Stage) error { | ||||||
| stack := p.findPulumiStackFromClusterFQDN(ctx, s.States.ServerFQDN) | ||||||
| stack := p.findStackFromClusterFQDN(ctx, s.States.ServerFQDN) | ||||||
| if stack == nil { | ||||||
| log.Info().Msgf("did not find a matching Pulumi stack for %s", s.States.ServerFQDN) | ||||||
| return nil | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package stage | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can import "github.com/stretchr/testify/assert" and "github.com/stretchr/testify/require" here and use assert/require libraries below. You can check client_test.go as an example. |
||
| ) | ||
|
|
||
| func TestFindBluerayStackFromClusterFQDN(t *testing.T) { | ||
| // Create a recorder with minimal initialization for testing | ||
| recorder := &PulumiMySQLRunRecorder{} | ||
|
|
||
| // Test FQDN | ||
| testFQDN := "xlarge-b109n-yabin-eng.k9b9rz3nk2.staging.cvpc.lakehouse.test.cloud.ibm.com" | ||
| expectedClusterName := "xlarge-b109n-yabin-eng" | ||
|
|
||
| // Call the function | ||
| ctx := context.Background() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context can be removed from findBluerayStackFromClusterFQDN |
||
| resource := recorder.findBluerayStackFromClusterFQDN(ctx, testFQDN) | ||
|
|
||
| // Verify resource is not nil | ||
| if resource == nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do require.NotNil(t, resource) |
||
| t.Fatalf("Expected non-nil resource, got nil") | ||
| } | ||
|
|
||
| // Verify the cluster FQDN | ||
| if resource.Outputs.ClusterFQDN != testFQDN { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do assert.Equal(t, testFQDN, resource.Outputs.ClusterFQDN) |
||
| t.Errorf("Expected ClusterFQDN to be %q, got %q", testFQDN, resource.Outputs.ClusterFQDN) | ||
| } | ||
|
|
||
| // Verify the cluster name | ||
| if resource.Outputs.ClusterName != expectedClusterName { | ||
| t.Errorf("Expected ClusterName to be %q, got %q", expectedClusterName, resource.Outputs.ClusterName) | ||
| } | ||
|
|
||
| // Verify the resource type | ||
| if resource.Type != PulumiResourceTypeStack { | ||
| t.Errorf("Expected Type to be %q, got %q", PulumiResourceTypeStack, resource.Type) | ||
| } | ||
|
|
||
| // Verify Created timestamp is not zero | ||
| if resource.Created.IsZero() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can do assert.False(t, resource.Created.IsZero()) |
||
| t.Error("Expected Created timestamp to be non-zero") | ||
| } | ||
| } | ||
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.