Comments (4)
Hi team,
I'm writing to contribute a change to the translateDeprecatedMetadataFields() function in pkg/model/dev.go
.
The current function prints a warning if the labels or annotations fields are used in a Dev manifest. I propose to modify the function to throw an error instead of a warning. This would make it clear to users that the deprecated fields should not be used.
Here is the proposed change:
func (dev *Dev) translateDeprecatedMetadataFields() {
if len(dev.Labels) > 0 {
panic("The field `labels` is deprecated and should not be used. Use the field `selector` instead.")
}
if len(dev.Annotations) > 0 {
panic("The field `annotations` is deprecated and should not be used. Use the field `metadata.annotations` instead.")
}
for indx, s := range dev.Services {
if len(s.Labels) > 0 {
panic(
"The field `%s.labels` is deprecated and should not be used. Use the field `selector` instead.",
s.Name,
)
}
if len(s.Annotations) > 0 {
panic(
"The field `annotations` is deprecated and should not be used. Use the field `%s.metadata.annotations` instead.",
s.Name,
)
}
}
}
I think this change is important because it will help to ensure that users are aware of the deprecated fields and that they are not used in new manifests.
I would be happy to implement this change and submit a PR. Please let me know if you have any questions.
Thanks,
Rishita Shaw
from okteto.
Thanks for contributing with your ideas, @rishitashaw!
In Go, it's preferred to return errors instead of throwing expections, like panicking. Also, deprecation is a great way to let the users know something is about to change, giving them time to migrate, if you throw an expections, it's blocking them from using the product.
from okteto.
I made the requested changes to handle deprecated fields in the Okteto CLI. Instead of warnings, the updated code returns errors for each deprecated field. This ensures clarity while allowing users to continue using the product.
Could you quickly review the modified code and let me know if it aligns with your expectations?
func (dev *Dev) translateDeprecatedMetadataFields() error {
if len(dev.Labels) > 0 {
message := "The field 'labels' is deprecated and will be removed in a future version. Use the field 'selector' instead (https://okteto.com/docs/reference/manifest/#selector)"
for k, v := range dev.Labels {
dev.Selector[k] = v
}
return errors.New(message)
}
if len(dev.Annotations) > 0 {
message := "The field 'annotations' is deprecated and will be removed in a future version. Use the field 'metadata.annotations' instead (https://okteto.com/docs/reference/manifest/#metadata)"
for k, v := range dev.Annotations {
dev.Metadata.Annotations[k] = v
}
return errors.New(message)
}
for indx, s := range dev.Services {
if len(s.Labels) > 0 {
message := fmt.Sprintf("The field '%s.labels' is deprecated and will be removed in a future version. Use the field 'selector' instead (https://okteto.com/docs/reference/manifest/#selector)", s.Name)
for k, v := range s.Labels {
dev.Services[indx].Selector[k] = v
}
return errors.New(message)
}
if len(s.Annotations) > 0 {
message := fmt.Sprintf("The field 'annotations' is deprecated and will be removed in a future version. Use the field '%s.metadata.annotations' instead (https://okteto.com/docs/reference/manifest/#metadata)", s.Name)
for k, v := range s.Annotations {
dev.Services[indx].Metadata.Annotations[k] = v
}
return errors.New(message)
}
}
return nil
}
from okteto.
Hi @andreafalzetti,
I'm writing to follow up on my previous message about the change to the translateDeprecatedMetadataFields() function in pkg/model/dev.go.
In addition, I'll modify the error messages in the following format to maintain idomaticity in the code: return fmt.Errorf(errorMessage)
I'd like to ask if you'd be willing to assign this change to me so that I can start working on it. I'm happy to answer any questions you have.
Thanks,
Rishita
from okteto.
Related Issues (20)
- Review Dev.Args: add support & docs or remove?
- Refine Labels for Development Environments
- If my Okteto manifest is specifying some `resources.limits` but not `resources.requests` we are setting the limits as requests HOT 1
- [CLI Quality] Modify docs reflecting updates about PR Review
- [CLI Quality] Research if a bot can help us improve the review process
- I got a panic error when executing `okteto up` and my `resources.requests` are too high
- okteto cli logs are not properly displayed in windows powershell HOT 1
- Dependency update request: `mixpanel/mixpanel-go` HOT 1
- `timeout` doesn't return any error after specified time elapsed
- okteto up --command doesn't handle commands with positional arguments
- Panic when `bash` is not installed HOT 1
- support deleteing multiple contexts at once HOT 4
- Exclude one or more applications in a namespace from sleeping HOT 2
- "okteto preview endpoints -o md" includes system messages
- "okteto preview endpoints $NAME -ojson" produces invalid json HOT 1
- `okteto destroy` on remote display confusing logs
- test issue
- add `--reuse-labels` to redeploy a dev environment and do not overwrite current dev environment labels HOT 1
- add subcomand `list` to support `okteto pipeline list`
- add flag `--label <name>` to `okteto pipeline list` command
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okteto.