Skip to content
Draft
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
8 changes: 5 additions & 3 deletions v1/providers/sfcomputev2/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func sanitizeSFCName(name string) string {
return name
}

func makeSFCName(refID string, tags v1.Tags) string {
return sanitizeSFCName(refID + "-" + tags["dev-plane-x-environmentId"])
}

func (c *SFCClientV2) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) {
c.logger.Debug(ctx, "sfcv2: CreateInstance start",
v1.LogField("name", attrs.Name),
Expand All @@ -61,9 +65,7 @@ func (c *SFCClientV2) CreateInstance(ctx context.Context, attrs v1.CreateInstanc
CloudInitUserData: &cloudInit,
Tags: tags,
}
// name is optional; sanitize the requested name to SFC's format and send it only if
// something valid remains. Otherwise omit it — identity is preserved in the tags above.
if name := sanitizeSFCName(attrs.Name); sfcNamePattern.MatchString(name) {
if name := makeSFCName(attrs.RefID, attrs.Tags); sfcNamePattern.MatchString(name) {
req.Name = &name
}
resp, err := c.client.createInstance(ctx, req)
Expand Down
23 changes: 23 additions & 0 deletions v1/providers/sfcomputev2/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,26 @@ func TestNormalizeTerminateInstanceErrorPreservesRetryableFailure(t *testing.T)

require.ErrorIs(t, err, providerErr)
}

func TestMakeSFCNameIsDeterministic(t *testing.T) {
t.Parallel()

tags := v1.Tags{"dev-plane-x-environmentId": "p82qfn5qs"}

first := makeSFCName("inst-2toqsvHXfalevkjPXY2QNJZL9HF", tags)
second := makeSFCName("inst-2toqsvHXfalevkjPXY2QNJZL9HF", tags)

require.Equal(t, first, second)
}

func TestMakeSFCNameIsUniquePerInstance(t *testing.T) {
t.Parallel()

// Same environment, two instances: re-provisioning must not reuse the previous name.
tags := v1.Tags{"dev-plane-x-environmentId": "p82qfn5qs"}

first := makeSFCName("inst-2toqsvHXfalevkjPXY2QNJZL9HF", tags)
second := makeSFCName("inst-2gAgPPd3QC1nmSjaWg8kc7UfyDx", tags)

require.NotEqual(t, first, second)
}
Loading