Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Fix reverse translation issue#205

Merged
istio-testing merged 6 commits intoistio:masterfrom
richardwxn:fix-reversetranslate
Aug 17, 2019
Merged

Fix reverse translation issue#205
istio-testing merged 6 commits intoistio:masterfrom
richardwxn:fix-reversetranslate

Conversation

@richardwxn
Copy link
Copy Markdown
Contributor

@richardwxn richardwxn commented Aug 16, 2019

  1. Minor bug fix
  2. Actually we don't need to unmarshall input values.yaml to values.types struct first and then marshall, which would lose some settings that don't have translation mappings. We can just take the input values.yaml value and do the reverse translation so that all untranslated path can be populated to common.values of different components.

@googlebot googlebot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Aug 16, 2019
@istio-testing istio-testing added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 16, 2019

func valueFileFilter(path string) bool {
return filepath.Base(path) == "values.yaml"
return filepath.Ext(path) == YAMLSuffix && strings.HasPrefix(filepath.Base(path), "values")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm concerned this is not going to be robust. we're relying on a filename being of the form values*.yaml - is there a better way to check for this, like file position wrt. charts root?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I checked the helm package implementation, it just check whether the file name equals "values.yaml", like what was implemented here before. That would work for installer files, but I am thinking the requirement should not be too strict because we have seen "values*.yaml" naming.

I am not sure whether it is necessary to validate the file schema or content here, instead I think it might be more clear to just give user message what files are being translated or not.

}

cuPath := newPS + ".cpu.targetAverageUtilization"
cuVal, found, err := name.GetFromTreePath(valueTree, util.ToYAMLPath(cuPath))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the operation here should probably be in a helper function - it's too detailed to follow at this level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the translateHPASpec function is already helper function to handle special translation, and since each hpa setting has slightly different handling so is not easy to extract general ways from it. So I try to refactor the logic inside this function.

return err
}
log.Infof("path has value in helm Value.yaml tree, mapping to output path %s", outPath)
if err := tpath.WriteNode(cpSpecTree, util.ToYAMLPath(outPath+".scaleTargetRef"), st); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

overall, i think the code above has repeated code that could be refactored at least to use helper function(s), if not to use a for loop and passing a list of mappings to it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would try to refactor and consolidate the repeating logic. But even that we can't really just do a simple mapping as there is some minor difference to handle different settings, only minReplica and maxReplicas are handled the exactly same way

@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 16, 2019
asVal, found, err := name.GetFromTreePath(valueTree, util.ToYAMLPath(valPath))
if found && err == nil {
log.Infof("path has value in helm Value.yaml tree, mapping to output path %s", outPath)
if key == ".cpu.targetAverageUtilization" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rather than checking for a special key, it's better to move this outside the loop, then have both this and the loop code call the same helper function if possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed the special key out of the loop

@richardwxn richardwxn force-pushed the fix-reversetranslate branch from 7f7ba45 to d5a7167 Compare August 16, 2019 23:25
"github.com/ghodss/yaml"
"github.com/gogo/protobuf/jsonpb"
"github.com/spf13/cobra"
"path/filepath"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

File is not goimports-ed (from goimports)

Suggested change
"path/filepath"

@ostromart
Copy link
Copy Markdown
Contributor

/cherrypick release-1.3

@istio-testing
Copy link
Copy Markdown

@ostromart: new pull request created: #220

Details

In response to this:

/cherrypick release-1.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

ostromart pushed a commit to ostromart/operator that referenced this pull request Aug 20, 2019
* Fix reverse translation issue

* Address hpa spec issues

* Refactor

* Second version of refactor

* Address comment

* lint
istio-testing pushed a commit that referenced this pull request Aug 21, 2019
* Eliminate vfsgen again. (#200)

* Fix build commmand for installing go-bindata (#202)

* Update makefile for proto related rules (#169)

* Update makefile for proto related rules to work for new system

* Address comments

* Add doc gen

* Upload updated pb.go files

* Update common

* Address comment

* Merge two install sections into one (#203)

* Merge two install sections into one

* Change section title

* Update to 2019-08-16 commonfiles (#207)

Enable MacOS based container builds.

Depends-On: istio/common-files#30
Depends-On: istio/tools#274

* support resource type for k8s mapping. (#206)

* support resource type for k8s mapping.

* apply comments.

* Fix reverse translation issue (#205)

* Fix reverse translation issue

* Address hpa spec issues

* Refactor

* Second version of refactor

* Address comment

* lint

* Changes to API for mesh config integration (#210)

* Changes to API for mesh config integration

* Review comments, add strategy

* Add strategy to k8s settings

* Fix unit tests

* update doc. (#212)

* update doc.

* apply comments.

* update link with recent source.

* Clean up values (#214)

* remove invalid and duplicated fields. (#217)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants