Skip to content

Commit

Permalink
Merge pull request #4621 from nkubala/tag-docs
Browse files Browse the repository at this point in the history
Fix CustomTagger docs
  • Loading branch information
tejal29 authored Aug 4, 2020
2 parents 3f842dd + 6954472 commit 1e0e9dd
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
11 changes: 8 additions & 3 deletions docs/content/en/docs/references/yaml/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,14 @@ function* template(definitions, parentDefinition, ref, ident, parent) {

// This definition is an array
if (definition.items && definition.items.$ref) {
yield html`
${template(definitions, definition, definition.items.$ref, ident + 1, path)}
`;
// don't infinitely recurse into nested tagger components
if (definition.items.$ref === "#/definitions/TaggerComponent") {
yield html ``;
} else {
yield html`
${template(definitions, definition, definition.items.$ref, ident + 1, path)}
`;
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions docs/content/en/schemas/v2beta6.json
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,45 @@
"description": "specifies which local files to sync to remote folders.",
"x-intellij-html-description": "specifies which local files to sync to remote folders."
},
"TagPolicy": {
"properties": {
"customTemplate": {
"$ref": "#/definitions/CustomTemplateTagger",
"description": "*beta* tags images with a configurable template string *composed of other taggers*.",
"x-intellij-html-description": "<em>beta</em> tags images with a configurable template string <em>composed of other taggers</em>."
},
"dateTime": {
"$ref": "#/definitions/DateTimeTagger",
"description": "*beta* tags images with the build timestamp.",
"x-intellij-html-description": "<em>beta</em> tags images with the build timestamp."
},
"envTemplate": {
"$ref": "#/definitions/EnvTemplateTagger",
"description": "*beta* tags images with a configurable template string.",
"x-intellij-html-description": "<em>beta</em> tags images with a configurable template string."
},
"gitCommit": {
"$ref": "#/definitions/GitTagger",
"description": "*beta* tags images with the git tag or commit of the artifact's workspace.",
"x-intellij-html-description": "<em>beta</em> tags images with the git tag or commit of the artifact's workspace."
},
"sha256": {
"$ref": "#/definitions/ShaTagger",
"description": "*beta* tags images with their sha256 digest.",
"x-intellij-html-description": "<em>beta</em> tags images with their sha256 digest."
}
},
"preferredOrder": [
"gitCommit",
"sha256",
"envTemplate",
"dateTime",
"customTemplate"
],
"additionalProperties": false,
"description": "contains all the configuration for the tagging step.",
"x-intellij-html-description": "contains all the configuration for the tagging step."
},
"TaggerComponent": {
"anyOf": [
{
Expand Down
19 changes: 15 additions & 4 deletions hack/schemas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ type Definition struct {
Examples []string `json:"examples,omitempty"`
Enum []string `json:"enum,omitempty"`

inlines []*Definition
tags string
inlines []*Definition
tags string
skipTrim bool
}

func main() {
Expand Down Expand Up @@ -238,7 +239,8 @@ func (g *schemaGenerator) newDefinition(name string, t ast.Expr, comment string,
if strings.Contains(field.Tag.Value, "inline") {
def.PreferredOrder = append(def.PreferredOrder, "<inline>")
def.inlines = append(def.inlines, &Definition{
Ref: defPrefix + field.Type.(*ast.Ident).Name,
Ref: defPrefix + field.Type.(*ast.Ident).Name,
skipTrim: strings.Contains(field.Tag.Value, "skipTrim"),
})
continue
}
Expand Down Expand Up @@ -354,6 +356,9 @@ func (g *schemaGenerator) Apply(inputPath string) ([]byte, error) {
}

for _, inlineStruct := range def.inlines {
if inlineStruct.skipTrim {
continue
}
ref := strings.TrimPrefix(inlineStruct.Ref, defPrefix)
inlines = append(inlines, ref)
}
Expand Down Expand Up @@ -435,7 +440,13 @@ func (g *schemaGenerator) Apply(inputPath string) ([]byte, error) {
}

for _, ref := range inlines {
delete(definitions, ref)
existingDef, ok := definitions[ref]
if !ok {
continue
}
if !existingDef.skipTrim {
delete(definitions, ref)
}
}

schema := Schema{
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ type TaggerComponent struct {
Name string `yaml:"name,omitempty"`

// Component is a tagging strategy to be used in CustomTemplateTagger.
Component TagPolicy `yaml:",inline"`
Component TagPolicy `yaml:",inline" yamltags:"skipTrim"`
}

// BuildType contains the specific implementation and parameters needed
Expand Down
22 changes: 22 additions & 0 deletions pkg/skaffold/yamltags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func processTags(yamltags string, val reflect.Value, parentStruct reflect.Value,
Field: field,
Parent: parentStruct,
}
case "skipTrim":
yt = &skipTrimTag{
Field: field,
}
default:
logrus.Panicf("unknown yaml tag in %s", yamltags)
}
Expand Down Expand Up @@ -166,6 +170,24 @@ func (oot *oneOfTag) Process(val reflect.Value) error {
return nil
}

type skipTrimTag struct {
Field reflect.StructField
}

func (tag *skipTrimTag) Load(s []string) error {
return nil
}

func (tag *skipTrimTag) Process(val reflect.Value) error {
if isZeroValue(val) {
if tags, ok := tag.Field.Tag.Lookup("yaml"); ok {
return fmt.Errorf("skipTrim value not set: %s", strings.Split(tags, ",")[0])
}
return fmt.Errorf("skipTrim value not set: %s", tag.Field.Name)
}
return nil
}

func isZeroValue(val reflect.Value) bool {
if val.Kind() == reflect.Invalid {
return true
Expand Down

0 comments on commit 1e0e9dd

Please sign in to comment.