Giter Site home page Giter Site logo

Comments (4)

rishitashaw avatar rishitashaw commented on May 24, 2024

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.

andreafalzetti avatar andreafalzetti commented on May 24, 2024

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.

rishitashaw avatar rishitashaw commented on May 24, 2024

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.

rishitashaw avatar rishitashaw commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.