Skip to content

Commit

Permalink
Upgrade ytt version to latest release
Browse files Browse the repository at this point in the history
update the ytt package ref

Signed-off-by: Devanshu <[email protected]>
  • Loading branch information
devanshuVmware committed Dec 10, 2024
1 parent 9182d4f commit c337b97
Show file tree
Hide file tree
Showing 182 changed files with 7,677 additions and 3,379 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module carvel.dev/kapp

go 1.23.3
go 1.23.2

require (
carvel.dev/ytt v0.51.0
github.com/cppforlife/cobrautil v0.0.0-20221130162803-acdfead391ef
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835
github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14
github.com/cppforlife/go-patch v0.0.0-20240118020416-2147782e467b
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-version v1.6.0
github.com/k14s/difflib v0.0.0-20240118055029-596a7a5585c3
github.com/k14s/ytt v0.36.0
github.com/mitchellh/go-wordwrap v1.0.1
github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11
github.com/spf13/cobra v1.8.1
Expand Down
283 changes: 4 additions & 279 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg/kapp/resourcesmisc/wait_rule_contract_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"fmt"

ctlres "carvel.dev/kapp/pkg/kapp/resources"
cmdtpl "github.com/k14s/ytt/pkg/cmd/template"
"github.com/k14s/ytt/pkg/cmd/ui"
"github.com/k14s/ytt/pkg/files"
cmdtpl "carvel.dev/ytt/pkg/cmd/template"
"carvel.dev/ytt/pkg/cmd/ui"
"carvel.dev/ytt/pkg/files"
"sigs.k8s.io/yaml"
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/kapp/yttresmod/overlay_contract_v1_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"fmt"

ctlres "carvel.dev/kapp/pkg/kapp/resources"
cmdtpl "github.com/k14s/ytt/pkg/cmd/template"
"github.com/k14s/ytt/pkg/cmd/ui"
"github.com/k14s/ytt/pkg/files"
cmdtpl "carvel.dev/ytt/pkg/cmd/template"
"carvel.dev/ytt/pkg/cmd/ui"
"carvel.dev/ytt/pkg/files"
"sigs.k8s.io/yaml"
)

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// Copyright 2020 VMware, Inc.
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package template

import (
"encoding/json"

"github.com/k14s/ytt/pkg/cmd/ui"
"github.com/k14s/ytt/pkg/files"
"github.com/spf13/cobra"
"carvel.dev/ytt/pkg/cmd/ui"
"carvel.dev/ytt/pkg/files"
)

type BulkFilesSourceOpts struct {
bulkIn string
bulkOut bool
}

func (s *BulkFilesSourceOpts) Set(cmd *cobra.Command) {
cmd.Flags().StringVar(&s.bulkIn, "bulk-in", "", "Accept files in bulk format")
cmd.Flags().BoolVar(&s.bulkOut, "bulk-out", false, "Output files in bulk format")
// Set registers "bulk" flags and wires-up those flags up to this
// BulkFilesSourceOpts to be set when the corresponding cobra.Command is executed.
func (s *BulkFilesSourceOpts) Set(cmdFlags CmdFlags) {
cmdFlags.StringVar(&s.bulkIn, "bulk-in", "", "Accept files in bulk format")
cmdFlags.BoolVar(&s.bulkOut, "bulk-out", false, "Output files in bulk format")
}

type BulkFilesSource struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// Copyright 2020 VMware, Inc.
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package template

import (
"fmt"
"time"

"github.com/k14s/ytt/pkg/cmd/ui"
"github.com/k14s/ytt/pkg/files"
"github.com/k14s/ytt/pkg/workspace"
"github.com/k14s/ytt/pkg/yamlmeta"
"github.com/spf13/cobra"
"carvel.dev/ytt/pkg/cmd/ui"
"carvel.dev/ytt/pkg/files"
"carvel.dev/ytt/pkg/schema"
"carvel.dev/ytt/pkg/workspace"
"carvel.dev/ytt/pkg/workspace/datavalues"
"carvel.dev/ytt/pkg/yamlmeta"
)

// Options both contains the configuration for a "template" command AND the
// top-level implementation of that command.
//
// For most intents and purposes, RunWithFiles() is the entrypoint.
type Options struct {
IgnoreUnknownComments bool
ImplicitMapKeyOverrides bool
Expand All @@ -37,39 +43,40 @@ type Output struct {
Err error
}

// FileSource provides both a means of loading from sources (i.e. Input) and rendering into sinks (i.e. Output)
type FileSource interface {
HasInput() bool
HasOutput() bool
Input() (Input, error)
// Output renders the results (i.e. an instance of Output) to the configured output/sink of this FileSource
Output(Output) error
}

var _ []FileSource = []FileSource{&BulkFilesSource{}, &RegularFilesSource{}}

// NewOptions initializes a new instance of template.Options.
func NewOptions() *Options {
return &Options{}
var opts files.SymlinkAllowOpts
return &Options{
RegularFilesSourceOpts: RegularFilesSourceOpts{SymlinkAllowOpts: &opts},
DataValuesFlags: DataValuesFlags{SymlinkAllowOpts: &opts},
}
}

func NewCmd(o *Options) *cobra.Command {
cmd := &cobra.Command{
Use: "template",
Aliases: []string{"t", "tpl"},
Short: "Process YAML templates (deprecated; use top-level command -- e.g. `ytt -f-` instead of `ytt template -f-`)",
RunE: func(c *cobra.Command, args []string) error { return o.Run() },
}
cmd.Flags().BoolVar(&o.IgnoreUnknownComments, "ignore-unknown-comments", false,
// BindFlags registers template flags for template command.
func (o *Options) BindFlags(cmdFlags CmdFlags) {
cmdFlags.BoolVar(&o.IgnoreUnknownComments, "ignore-unknown-comments", false,
"Configure whether unknown comments are considered as errors (comments that do not start with '#@' or '#!')")
cmd.Flags().BoolVar(&o.ImplicitMapKeyOverrides, "implicit-map-key-overrides", false,
cmdFlags.BoolVar(&o.ImplicitMapKeyOverrides, "implicit-map-key-overrides", false,
"Configure whether implicit map keys overrides are allowed")
cmd.Flags().BoolVarP(&o.StrictYAML, "strict", "s", false, "Configure to use _strict_ YAML subset")
cmd.Flags().BoolVar(&o.Debug, "debug", false, "Enable debug output")
cmd.Flags().BoolVar(&o.InspectFiles, "files-inspect", false, "Inspect files")

o.BulkFilesSourceOpts.Set(cmd)
o.RegularFilesSourceOpts.Set(cmd)
o.FileMarksOpts.Set(cmd)
o.DataValuesFlags.Set(cmd)
return cmd
cmdFlags.BoolVarP(&o.StrictYAML, "strict", "s", false, "Configure to use _strict_ YAML subset")
cmdFlags.BoolVar(&o.Debug, "debug", false, "Enable debug output")
cmdFlags.BoolVar(&o.InspectFiles, "files-inspect", false, "Determine the set of files that would be processed and display that result")

o.BulkFilesSourceOpts.Set(cmdFlags)
o.RegularFilesSourceOpts.Set(cmdFlags)
o.FileMarksOpts.Set(cmdFlags)
o.DataValuesFlags.Set(cmdFlags)
}

func (o *Options) Run() error {
Expand Down Expand Up @@ -114,11 +121,14 @@ func (o *Options) RunWithFiles(in Input, ui ui.UI) Output {
return Output{Err: err}
}

libraryExecutionFactory := workspace.NewLibraryExecutionFactory(ui, workspace.TemplateLoaderOpts{
IgnoreUnknownComments: o.IgnoreUnknownComments,
ImplicitMapKeyOverrides: o.ImplicitMapKeyOverrides,
StrictYAML: o.StrictYAML,
})
libraryExecutionFactory := workspace.NewLibraryExecutionFactory(
ui,
workspace.TemplateLoaderOpts{
IgnoreUnknownComments: o.IgnoreUnknownComments,
ImplicitMapKeyOverrides: o.ImplicitMapKeyOverrides,
StrictYAML: o.StrictYAML,
},
o.DataValuesFlags.SkipValidation)

libraryCtx := workspace.LibraryExecutionContext{Current: rootLibrary, Root: rootLibrary}
rootLibraryExecution := libraryExecutionFactory.New(libraryCtx)
Expand All @@ -128,6 +138,18 @@ func (o *Options) RunWithFiles(in Input, ui ui.UI) Output {
return Output{Err: err}
}

if o.DataValuesFlags.InspectSchema {
return o.inspectSchema(schema)
}

schemaType, err := o.RegularFilesSourceOpts.OutputType.Schema()
if err != nil {
return Output{Err: err}
}
if schemaType == RegularFilesOutputTypeOpenAPI {
return Output{Err: fmt.Errorf("Output type currently only supported for data values schema (i.e. include --data-values-schema-inspect)")}
}

values, libraryValues, err := rootLibraryExecution.Values(valuesOverlays, schema)
if err != nil {
return Output{Err: err}
Expand All @@ -136,11 +158,7 @@ func (o *Options) RunWithFiles(in Input, ui ui.UI) Output {
libraryValues = append(libraryValues, libraryValuesOverlays...)

if o.DataValuesFlags.Inspect {
return Output{
DocSet: &yamlmeta.DocumentSet{
Items: []*yamlmeta.Document{values.Doc},
},
}
return o.inspectDataValues(values)
}

result, err := rootLibraryExecution.Eval(values, libraryValues, librarySchemas)
Expand All @@ -151,6 +169,31 @@ func (o *Options) RunWithFiles(in Input, ui ui.UI) Output {
return Output{Files: result.Files, DocSet: result.DocSet}
}

func (o *Options) inspectDataValues(values *datavalues.Envelope) Output {
return Output{
DocSet: &yamlmeta.DocumentSet{
Items: []*yamlmeta.Document{values.Doc},
},
}
}

func (o *Options) inspectSchema(dataValuesSchema *datavalues.Schema) Output {
format, err := o.RegularFilesSourceOpts.OutputType.Schema()
if err != nil {
return Output{Err: err}
}
if format == RegularFilesOutputTypeOpenAPI {
openAPIDoc := schema.NewOpenAPIDocument(dataValuesSchema.GetDocumentType())
return Output{
DocSet: &yamlmeta.DocumentSet{
Items: []*yamlmeta.Document{openAPIDoc.AsDocument()},
},
}
}
return Output{Err: fmt.Errorf("Data values schema export only supported in OpenAPI v3 format; specify format with --output=%s flag",
RegularFilesOutputTypeOpenAPI)}
}

func (o *Options) pickSource(srcs []FileSource, pickFunc func(FileSource) bool) FileSource {
for _, src := range srcs {
if pickFunc(src) {
Expand Down
20 changes: 20 additions & 0 deletions vendor/carvel.dev/ytt/pkg/cmd/template/cmd_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package template

// CmdFlags interface decouples this package from
// depending on cobra.Command/flags concrete types.
type CmdFlags interface {
BoolVar(p *bool, name string, value bool, usage string)
BoolVarP(p *bool, name, shorthand string, value bool, usage string)

StringVar(p *string, name string, value string, usage string)
StringVarP(p *string, name, shorthand string, value string, usage string)

StringArrayVar(p *[]string, name string, value []string, usage string)
StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string)

StringSliceVar(p *[]string, name string, value []string, usage string)
StringSliceVarP(p *[]string, name, shorthand string, value []string, usage string)
}
28 changes: 28 additions & 0 deletions vendor/carvel.dev/ytt/pkg/cmd/template/data_values_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 The Carvel Authors.
// SPDX-License-Identifier: Apache-2.0

package template

import (
"carvel.dev/ytt/pkg/yamlmeta"
"carvel.dev/ytt/pkg/yttlibrary/overlay"
)

type DataValuesFile struct {
doc *yamlmeta.Document
}

func NewDataValuesFile(doc *yamlmeta.Document) DataValuesFile {
return DataValuesFile{doc.DeepCopy()}
}

func (f DataValuesFile) AsOverlay() (*yamlmeta.Document, error) {
doc := f.doc.DeepCopy()

err := overlay.AnnotateForPlainMerge(doc)
if err != nil {
return nil, err
}

return doc, nil
}
Loading

0 comments on commit c337b97

Please sign in to comment.