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

Resource cpus value has wrong type when calling MarshalYAML export #712

Open
donknap opened this issue Nov 20, 2024 · 2 comments
Open

Resource cpus value has wrong type when calling MarshalYAML export #712

donknap opened this issue Nov 20, 2024 · 2 comments

Comments

@donknap
Copy link

donknap commented Nov 20, 2024

Original Yaml :

services:
  nginx_proxy:
    image: nginx:latest
    deploy:
      resources:
        limits:
          cpus: 4.00
          memory: 500M

code:

// make 
overrideYaml, err := compose.Project.MarshalYAML()
if err != nil {
return nil, err
}

error:

图片

@ndeloof
Copy link
Collaborator

ndeloof commented Nov 28, 2024

cpus is defined in compose spec schema as a number, which indeed can be set as a float but this doesn't mean the notation MUST be decimal. A plain integer is a valid value

@ndeloof
Copy link
Collaborator

ndeloof commented Nov 28, 2024

see go-yaml/yaml#430
A possible workaround is to define a custom marshaller:

func (u NanoCPUs) MarshalYAML() (interface{}, error) {
	return yaml.Node{Kind: yaml.ScalarNode, Tag: "!!float", Value: fmt.Sprintf("%f", u)}, nil
}

still, this is not strictly necessary to conform to yaml

Could you please clarify the usage that requires marshaled model to use a floating point notation?

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

No branches or pull requests

2 participants