Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Support defining image paths for HelmReleases #2249

Merged
merged 5 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion bin/kubeyaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
docker run --rm -i quay.io/squaremo/kubeyaml:0.6.1 "$@"
docker run --rm -i quay.io/squaremo/kubeyaml:0.7.0 "$@"
9 changes: 5 additions & 4 deletions cluster/kubernetes/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ perhaps verify its presence using kubectl.
`, obj)}
}

func UpdateNotSupportedError(kind string) error {
func UpdateNotSupportedError(kind string) *fluxerr.Error {
return &fluxerr.Error{
Type: fluxerr.User,
Err: fmt.Errorf("updating resource kind %q not supported", kind),
Help: `Flux does not support updating ` + kind + ` resources.

This may be because those resources do not use images, or because it
is a new kind of resource in Kubernetes, and Flux does not support it
yet.
This may be because those resources do not use images, you are trying
to use a YAML dot notation path annotation for a non HelmRelease
resource, or because it is a new kind of resource in Kubernetes, and
Flux does not support it yet.

If you can use a Deployment instead, Flux can work with
those. Otherwise, you may have to update the resource manually (e.g.,
Expand Down
7 changes: 7 additions & 0 deletions cluster/kubernetes/kubeyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ func (k KubeYAML) Annotate(in []byte, ns, kind, name string, policies ...string)
return execKubeyaml(in, args)
}

// Set calls the kubeyaml subcommand `set` with the arguments given.
func (k KubeYAML) Set(in []byte, ns, kind, name string, values ...string) ([]byte, error) {
args := []string{"set", "--namespace", ns, "--kind", kind, "--name", name}
args = append(args, values...)
return execKubeyaml(in, args)
}

func execKubeyaml(in []byte, args []string) ([]byte, error) {
cmd := exec.Command("kubeyaml", args...)
out := &bytes.Buffer{}
Expand Down
27 changes: 26 additions & 1 deletion cluster/kubernetes/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,32 @@ func (m *manifests) ParseManifest(def []byte, source string) (map[string]resourc
}

func (m *manifests) SetWorkloadContainerImage(def []byte, id resource.ID, container string, image image.Ref) ([]byte, error) {
return updateWorkload(def, id, container, image)
resources, err := m.ParseManifest(def, "stdin")
if err != nil {
return nil, err
}
res, ok := resources[id.String()]
if !ok {
return nil, fmt.Errorf("resource %s not found", id.String())
}
// Check if the workload is a HelmRelease, and try to resolve an image
// map for the given container to perform an update based on mapped YAML
// dot notation paths. If resolving the map fails (either because there
// is no map for the given container, or the mapping does not resolve
// in to a valid image ref), it returns the error.
//
// NB: we do this here and not in e.g. the `resource` package, to ensure
// everything _outside_ this package only knows about Kubernetes native
// containers, and not the dot notation YAML paths we invented for custom
// Helm value structures.
if hr, ok := res.(*kresource.HelmRelease); ok {
paths, err := hr.GetContainerImageMap(container)
if err != nil {
return nil, err
}
return updateWorkloadImagePaths(def, id, paths, image)
}
return updateWorkloadContainer(def, id, container, image)
}

func (m *manifests) CreateManifestPatch(originalManifests, modifiedManifests []byte, originalSource, modifiedSource string) ([]byte, error) {
Expand Down
8 changes: 8 additions & 0 deletions cluster/kubernetes/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ func TestUpdatePolicies(t *testing.T) {
},
wantErr: true,
},
{
name: "add tag policy with alternative prefix does not change existing prefix",
in: []string{"filter.fluxcd.io/nginx", "glob:*"},
out: []string{"filter.fluxcd.io/nginx", "glob:*"},
update: resource.PolicyUpdate{
Add: policy.Set{policy.TagPrefix("nginx"): "glob:*"},
},
},
{
name: "set tag to all containers",
in: nil,
Expand Down
Loading