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

chore(vclusterctl): check for pre 0.20 values #1738

Merged

Conversation

johannesfrey
Copy link
Contributor

@johannesfrey johannesfrey commented May 2, 2024

What issue type does this pull request address? (keep at least one, remove the others)
/kind enhancement

What does this pull request do? Which issues does it resolve? (use resolves #<issue_number> if possible)
Resolves ENG-3573

Please provide a short message that should be published in the vcluster release notes
Provide checks that abort "vcluster create" when using pre-v0.20 formatting in values.yaml.

What else do we need to know?

Copy link

netlify bot commented May 2, 2024

Deploy Preview for vcluster-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 6ad1417
🔍 Latest deploy log https://app.netlify.com/sites/vcluster-docs/deploys/663b154da7018c0008e8b51e

@johannesfrey johannesfrey force-pushed the check-pre-0.20-values-vclusterctl-3 branch 22 times, most recently from 5ca8801 to f0c58c4 Compare May 7, 2024 10:03
@johannesfrey johannesfrey marked this pull request as ready for review May 7, 2024 10:04
@johannesfrey johannesfrey force-pushed the check-pre-0.20-values-vclusterctl-3 branch from f0c58c4 to 2960e22 Compare May 7, 2024 10:12
}

command := fmt.Sprintf("vcluster convert config --distro %s - <<EOF\n%s\nEOF", currentDistro, string(currentValues))
Copy link
Member

Choose a reason for hiding this comment

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

This will print a big chunk, can we not do something like:

helm get values ... | vcluster convert config ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. helm get values will retrieve the latest revision right? I tested locally and it looks like it 🤔 And should we do a helm get values -a? Otherwise, if you happened to install it with default config via helm helm get values will return null.
Update: I made the helm command conditionally.

Copy link
Member

@FabianKramm FabianKramm left a comment

Choose a reason for hiding this comment

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

See my comments

Comment on lines 242 to 253
if err != nil {
if errors.Is(err, config.ErrInvalidConfig) {
cmd.log.Infof("If you are using the old values format, consider using %q to convert it to the new v0.20 format", "vcluster convert config")
if !errors.Is(err, config.ErrInvalidConfig) {
return err
}
return err
// TODO Delete after vCluster 0.19.x resp. the old config format is out of support.
// We cannot discriminate between k0s/k3s and eks/k8s. So we cannot prompt the actual values to convert, as this would cause false positives,
// because users are free to e.g. pass a k0s values file to a currently running k3s virtual cluster.
if isLegacyConfig(data) {
return fmt.Errorf("it appears you are using a vCluster configuration using pre-v0.20 formatting. Please run %q to convert the values to the latest format", "vcluster convert config")
}
// TODO end
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would maybe structure the if differently here

if errors.Is(err, config.ErrInvalidConfig) {
  if isLegacyConfig(data){
    return fmt.Errorf("it appears you are using a vCluster configuration using pre-v0.20 formatting. Please run %q to convert the values to the latest format", "vcluster convert config")
  }
} else if err != nil {
  return err
}

that is simpler to follow imho

Copy link
Contributor

Choose a reason for hiding this comment

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

btw don't we want to return the error if it's ErrInvalidConfig but not isLegacyConfig ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess so 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: The ErrInvalidConfig did not provide any benefit. It was actually a left-over from when the config unmarshaling looked different. So I changed it to a simple err check.

Comment on lines 383 to 388
values, err := yaml.Marshal(helmChart.Chart.Values)
if err != nil {
return nil, err
}

return values, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

here you can just do

return yaml.Marshal(helmChart.Chart.Values)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When going with Fabian's suggestion this func will be removed.

Comment on lines 368 to 381
releaseRaw, err := io.ReadAll(gz)
if err != nil {
return nil, err
}

helmChart := struct {
Chart struct {
Values map[string]interface{} `json:"values"`
} `json:"chart"`
}{}

// TODO end
if err := yaml.Unmarshal(releaseRaw, &helmChart); err != nil {
return nil, err
}
Copy link
Contributor

@facchettos facchettos May 7, 2024

Choose a reason for hiding this comment

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

can we use a decoder here instead of reading everything into memory or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When going with Fabian's suggestion this func will be removed.

pkg/cli/create_helm.go Outdated Show resolved Hide resolved
@johannesfrey johannesfrey force-pushed the check-pre-0.20-values-vclusterctl-3 branch from a3f09bc to 3cf3b82 Compare May 8, 2024 05:55
@FabianKramm FabianKramm merged commit 0e7521f into loft-sh:main May 8, 2024
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants