Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
instruct images.yaml parser with labels
Browse files Browse the repository at this point in the history
```feature user
It is now possible to instruct the component-cli image parser with labels instead of flags on the cli.
For detailed documentation see the generated doc.
```
  • Loading branch information
Tim Schrodi committed Mar 10, 2021
1 parent 4f36ef7 commit 946b9e2
Show file tree
Hide file tree
Showing 14 changed files with 616 additions and 309 deletions.
9 changes: 6 additions & 3 deletions docs/reference/components-cli_component-archive_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ components-cli component-archive create [component-archive-path] [flags]
### Options

```
--format CAOutputFormat output format of the component archive. Can be "fs", "tar" or "tgz"
-h, --help help for create
-o, --out string writes the resulting archive to the given path
-a, --archive string path to the component archive directory
--component-name string name of the component
--component-version string version of the component
-h, --help help for create
-w, --overwrite overwrites the existing component
--repo-ctx string [OPTIONAL] repository context url for component to upload. The repository url will be automatically added to the repository contexts.
```

### Options inherited from parent commands
Expand Down
24 changes: 21 additions & 3 deletions docs/reference/components-cli_image-vector_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ resources:
imageReference: gcr.io/google_containers/pause-amd64:3.1
</pre>

2. The image matches the given "--component-prefixes" which will add the image as label ("imagevector.gardener.cloud/images") to the "componentReference".
2. The image is defined by another component so the image is added as label ("imagevector.gardener.cloud/images") to the "componentReference".

Images that are defined by other components can be specified
1. [DEPRECATED] when the image's repository matches the given "--component-prefixes"
2. the image is labeled with "imagevector.gardener.cloud/component-reference"

If the component reference is not yet defined it will be automatically added.
If multiple images are defined for the same component reference they are added to the images list in the label.

Expand All @@ -51,14 +56,20 @@ images:
repository: eu.gcr.io/gardener-project/gardener/autoscaler/cluster-autoscaler
targetVersion: "< 1.16"
tag: "v0.10.0"
labels: # recommended bbut only needed when "--component-prefixes" is not defined
- name: imagevector.gardener.cloud/component-reference
value:
name: cla # defaults to image.name
componentName: github.com/gardener/autoscaler # defaults to image.sourceRepository
version: v0.10.0 # defaults to image.version
</pre>

<pre>
meta:
schemaVersion: 'v2'
...
componentReferences:
- name: cluster-autoscaler
- name: cla
componentName: github.com/gardener/autoscaler
version: v0.10.0
extraIdentity:
Expand All @@ -74,14 +85,21 @@ componentReferences:
targetVersion: '< 1.16'
</pre>

3. The image is defined as "--generic-dependency" which will add the image as label ("imagevector.gardener.cloud/images") to the component descriptor.
3. The image is a generic dependency where the actual images are defined by the overwrite.
A generic dependency image is not part of a component descriptors resource but will be added as label ("imagevector.gardener.cloud/images") to the component descriptor.

Generic dependencies can be defined by
1. [DEPRECATED] defined as "--generic-dependency=<image name>"
2. the label "imagevector.gardener.cloud/generic"

<pre>
images:
- name: hyperkube
sourceRepository: github.com/kubernetes/kubernetes
repository: k8s.gcr.io/hyperkube
targetVersion: "< 1.19"
labels: # only needed if "--generic-dependency" is not set
- name: imagevector.gardener.cloud/generic
</pre>

<pre>
Expand Down
14 changes: 10 additions & 4 deletions pkg/commands/componentarchive/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"fmt"
"os"

"github.com/go-logr/logr"
"github.com/mandelsoft/vfs/pkg/osfs"
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/gardener/component-cli/pkg/componentarchive"
"github.com/gardener/component-cli/pkg/logger"
)

// CreateOptions defines all options for the create command.
Expand All @@ -24,7 +26,7 @@ type CreateOptions struct {

// NewCreateCommand creates a new component descriptor
func NewCreateCommand(ctx context.Context) *cobra.Command {
opts := &ExportOptions{}
opts := &CreateOptions{}
cmd := &cobra.Command{
Use: "create [component-archive-path]",
Args: cobra.ExactArgs(1),
Expand All @@ -37,19 +39,22 @@ Create command creates a new component archive directory with a "component-descr
fmt.Println(err.Error())
os.Exit(1)
}
if err := opts.Run(ctx, osfs.New()); err != nil {
if err := opts.Run(ctx, logger.Log, osfs.New()); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Printf("Successfully created component archive at %s\n", opts.OutputPath)
fmt.Printf("Successfully created component archive at %s\n", args[0])
},
}
opts.AddFlags(cmd.Flags())
return cmd
}

// Run runs the export for a component archive.
func (o *CreateOptions) Run(ctx context.Context, fs vfs.FileSystem) error {
func (o *CreateOptions) Run(_ context.Context, log logr.Logger, fs vfs.FileSystem) error {
if o.Overwrite {
log.V(3).Info("overwrite enabled")
}
_, err := o.BuilderOptions.Build(fs)
return err
}
Expand All @@ -70,4 +75,5 @@ func (o *CreateOptions) validate() error {

func (o *CreateOptions) AddFlags(fs *pflag.FlagSet) {
o.BuilderOptions.AddFlags(fs)
fs.BoolVarP(&o.BuilderOptions.Overwrite, "overwrite", "w", false, "overwrites the existing component")
}
6 changes: 3 additions & 3 deletions pkg/commands/ctf/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ It is expected that the given path points to a CTF Archive`, o.CTFPath)
if err := ctfArchive.AddComponentArchiveWithName(
utils.CTFComponentArchiveFilename(ca.ComponentDescriptor.GetName(),
ca.ComponentDescriptor.GetVersion()),
ca,
o.ArchiveFormat,
); err != nil {
ca,
o.ArchiveFormat,
); err != nil {
return fmt.Errorf("unable to add component archive %q to ctf: %s", ca.ComponentDescriptor.GetName(), err.Error())
}
log.Info(fmt.Sprintf("Successfully added component archive from %q", caPath))
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/ctf/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var _ = Describe("Add", func() {
ctx := context.Background()
defer ctx.Done()
opts := cmd.AddOptions{
CTFPath: "/component.ctf",
ArchiveFormat: ctf.ArchiveFormatTar,
CTFPath: "/component.ctf",
ArchiveFormat: ctf.ArchiveFormatTar,
ComponentArchives: []string{"./00-ca"},
}

Expand Down
24 changes: 21 additions & 3 deletions pkg/commands/imagevector/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ resources:
imageReference: gcr.io/google_containers/pause-amd64:3.1
</pre>
2. The image matches the given "--component-prefixes" which will add the image as label ("imagevector.gardener.cloud/images") to the "componentReference".
2. The image is defined by another component so the image is added as label ("imagevector.gardener.cloud/images") to the "componentReference".
Images that are defined by other components can be specified
1. [DEPRECATED] when the image's repository matches the given "--component-prefixes"
2. the image is labeled with "imagevector.gardener.cloud/component-reference"
If the component reference is not yet defined it will be automatically added.
If multiple images are defined for the same component reference they are added to the images list in the label.
Expand All @@ -94,14 +99,20 @@ images:
repository: eu.gcr.io/gardener-project/gardener/autoscaler/cluster-autoscaler
targetVersion: "< 1.16"
tag: "v0.10.0"
labels: # recommended bbut only needed when "--component-prefixes" is not defined
- name: imagevector.gardener.cloud/component-reference
value:
name: cla # defaults to image.name
componentName: github.com/gardener/autoscaler # defaults to image.sourceRepository
version: v0.10.0 # defaults to image.version
</pre>
<pre>
meta:
schemaVersion: 'v2'
...
componentReferences:
- name: cluster-autoscaler
- name: cla
componentName: github.com/gardener/autoscaler
version: v0.10.0
extraIdentity:
Expand All @@ -117,14 +128,21 @@ componentReferences:
targetVersion: '< 1.16'
</pre>
3. The image is defined as "--generic-dependency" which will add the image as label ("imagevector.gardener.cloud/images") to the component descriptor.
3. The image is a generic dependency where the actual images are defined by the overwrite.
A generic dependency image is not part of a component descriptors resource but will be added as label ("imagevector.gardener.cloud/images") to the component descriptor.
Generic dependencies can be defined by
1. [DEPRECATED] defined as "--generic-dependency=<image name>"
2. the label "imagevector.gardener.cloud/generic"
<pre>
images:
- name: hyperkube
sourceRepository: github.com/kubernetes/kubernetes
repository: k8s.gcr.io/hyperkube
targetVersion: "< 1.19"
labels: # only needed if "--generic-dependency" is not set
- name: imagevector.gardener.cloud/generic
</pre>
<pre>
Expand Down
Loading

0 comments on commit 946b9e2

Please sign in to comment.