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

Fix CustomTagger docs #4621

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/content/en/docs/references/yaml/main.js
Original file line number Diff line number Diff line change
@@ -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)}
`;
}
}
}
}
39 changes: 39 additions & 0 deletions docs/content/en/schemas/v2beta6.json
Original file line number Diff line number Diff line change
@@ -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": [
{
19 changes: 15 additions & 4 deletions hack/schemas/main.go
Original file line number Diff line number Diff line change
@@ -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() {
@@ -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
}
@@ -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)
}
@@ -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{
2 changes: 1 addition & 1 deletion pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions pkg/skaffold/yamltags/tags.go
Original file line number Diff line number Diff line change
@@ -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)
}
@@ -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