Skip to content
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

Fix previews in SSA mode when there are replacements due to immutable fields #3053

Merged
merged 7 commits into from
Jun 26, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use k8s name generator
  • Loading branch information
rquitales committed Jun 25, 2024
commit 24c4a0ec71bf6ae3f31ce8fcf7fa5317fe2c8e1f
16 changes: 4 additions & 12 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/client-go/dynamic"
k8sopenapi "k8s.io/kubectl/pkg/util/openapi"
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
Expand Down Expand Up @@ -223,19 +224,10 @@
// creates with SSA enabled. This means that we currently always upsert the object.
if c.Preview &&
(apierrors.IsInvalid(err) && strings.Contains(err.Error(), apivalidation.FieldImmutableErrorMsg)) {
const previewSuffix = "-preview"
objName := c.Inputs.GetName()

// Set the name to have the "-preview" suffix. Ensure we don't have a string over 253 characters, which is
// the maximum length for a name in Kubernetes.
var previewName string
if len(objName) > 253-len(previewSuffix) {
previewName = objName[:253-len(previewSuffix)] + previewSuffix
} else {
previewName = objName + previewSuffix
}

previewName := names.SimpleNameGenerator.GenerateName(c.Inputs.GetName())
c.Host.Log(c.Context, diag.Info, c.URN, fmt.Sprintf("Preview creation failed due to immutable fields; retrying with name %q", previewName))

Check failure on line 228 in provider/pkg/await/await.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `c.Host.Log` is not checked (errcheck)
c.Inputs.SetName(previewName)

objYAML, errYaml := yaml.Marshal(c.Inputs.Object)
if errYaml != nil {
return err
Expand Down
Loading