Add delete, export, get image-update

This uses the established abstractions to implement the usual
subcommands for the ImageUpdateAutomation type.

I've called the sub-subcommand in each case `image-update`, as a
fairly safe shorthand for the much longer `image-update-automation`.

Signed-off-by: Michael Bridgen <michael@weave.works>
pull/538/head
Michael Bridgen 4 years ago
parent 433628791b
commit f316aff2d3

@ -94,7 +94,7 @@ func createAutoImageUpdateRun(cmd *cobra.Command, args []string) error {
}, },
Branch: imageUpdateArgs.branch, Branch: imageUpdateArgs.branch,
}, },
RunInterval: &metav1.Duration{Duration: interval}, Interval: metav1.Duration{Duration: interval},
Update: autov1.UpdateStrategy{ Update: autov1.UpdateStrategy{
Setters: &autov1.SettersStrategy{}, Setters: &autov1.SettersStrategy{},
}, },
@ -107,7 +107,7 @@ func createAutoImageUpdateRun(cmd *cobra.Command, args []string) error {
} }
if export { if export {
return printExport(exportImageUpdateAutomation(&update)) return printExport(exportImageUpdate(&update))
} }
// I don't need these until attempting to upsert the object, but // I don't need these until attempting to upsert the object, but
@ -189,21 +189,3 @@ func isImageUpdateAutomationReady(ctx context.Context, kubeClient client.Client,
return false, nil return false, nil
} }
} }
func exportImageUpdateAutomation(update *autov1.ImageUpdateAutomation) interface{} {
gvk := autov1.GroupVersion.WithKind("ImageUpdateAutomation") // TODO replace with constant
export := autov1.ImageUpdateAutomation{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,
APIVersion: gvk.GroupVersion().String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: update.Name,
Namespace: update.Namespace,
Labels: update.Labels,
Annotations: update.Annotations,
},
Spec: update.Spec,
}
return export
}

@ -0,0 +1,40 @@
/*
Copyright 2020 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"github.com/spf13/cobra"
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
)
var deleteImageUpdateCmd = &cobra.Command{
Use: "image-update [name]",
Short: "Delete an ImageUpdateAutomation object",
Long: "The delete auto image-update command deletes the given ImageUpdateAutomation from the cluster.",
Example: ` # Delete an image update automation
flux delete auto image-update latest-images
`,
RunE: deleteCommand{
humanKind: "image update automation",
container: genericContainer{&autov1.ImageUpdateAutomation{}},
}.run,
}
func init() {
deleteAutoCmd.AddCommand(deleteImageUpdateCmd)
}

@ -0,0 +1,93 @@
/*
Copyright 2020 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
)
var exportImageUpdateCmd = &cobra.Command{
Use: "image-update [name]",
Short: "Export ImageUpdateAutomation resources in YAML format",
Long: "The export image-update command exports one or all ImageUpdateAutomation resources in YAML format.",
Example: ` # Export all ImageUpdateAutomation resources
flux export auto image-update --all > updates.yaml
# Export a specific automation
flux export auto image-update latest-images > latest.yaml
`,
RunE: exportCommand{
object: exportableImageUpdate{&autov1.ImageUpdateAutomation{}},
list: exportableImageUpdateList{&autov1.ImageUpdateAutomationList{}},
}.run,
}
func init() {
exportAutoCmd.AddCommand(exportImageUpdateCmd)
}
// exportImageUpdate returns a value which has extraneous information
// stripped out.
func exportImageUpdate(item *autov1.ImageUpdateAutomation) interface{} {
gvk := autov1.GroupVersion.WithKind(autov1.ImageUpdateAutomationKind)
export := autov1.ImageUpdateAutomation{
TypeMeta: metav1.TypeMeta{
Kind: gvk.Kind,
APIVersion: gvk.GroupVersion().String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: item.Name,
Namespace: item.Namespace,
Labels: item.Labels,
Annotations: item.Annotations,
},
Spec: item.Spec,
}
return export
}
type exportableImageUpdate struct {
update *autov1.ImageUpdateAutomation
}
func (ex exportableImageUpdate) AsClientObject() runtime.Object {
return ex.update
}
func (ex exportableImageUpdate) Export() interface{} {
return exportImageUpdate(ex.update)
}
type exportableImageUpdateList struct {
list *autov1.ImageUpdateAutomationList
}
func (ex exportableImageUpdateList) AsClientObject() runtime.Object {
return ex.list
}
func (ex exportableImageUpdateList) Len() int {
return len(ex.list.Items)
}
func (ex exportableImageUpdateList) ExportAt(i int) interface{} {
return exportImageUpdate(&ex.list.Items[i])
}

@ -0,0 +1,77 @@
/*
Copyright 2020 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"strconv"
"strings"
"time"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
)
var getImageUpdateCmd = &cobra.Command{
Use: "image-update",
Short: "Get ImageUpdateAutomation statuses",
Long: "The get auto image-update command prints the status of ImageUpdateAutomation objects.",
Example: ` # List all image update automation object and their status
flux get auto image-update
# List image update automations from all namespaces
flux get auto image-update --all-namespaces
`,
RunE: getCommand{
list: &imageUpdateSummary{&autov1.ImageUpdateAutomationList{}},
}.run,
}
func init() {
getAutoCmd.AddCommand(getImageUpdateCmd)
}
type imageUpdateSummary struct {
*autov1.ImageUpdateAutomationList
}
func (s imageUpdateSummary) Len() int {
return len(s.Items)
}
func (s imageUpdateSummary) SummariseAt(i int, includeNamespace bool) []string {
item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions)
var lastRun string
if item.Status.LastAutomationRunTime != nil {
lastRun = item.Status.LastAutomationRunTime.Time.Format(time.RFC3339)
}
return append(nameColumns(&item, includeNamespace), status, msg, lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}
func (s imageUpdateSummary) Headers(includeNamespace bool) []string {
headers := []string{"Name", "Ready", "Message", "Last run", "Suspended"}
if includeNamespace {
return append(namespaceHeader, headers...)
}
return headers
}
func (s imageUpdateSummary) AsClientObject() runtime.Object {
return s.ImageUpdateAutomationList
}

@ -28,4 +28,5 @@ The delete auto sub-commands delete automation objects.
* [flux delete](flux_delete.md) - Delete sources and resources * [flux delete](flux_delete.md) - Delete sources and resources
* [flux delete auto image-policy](flux_delete_auto_image-policy.md) - Delete an ImagePolicy object * [flux delete auto image-policy](flux_delete_auto_image-policy.md) - Delete an ImagePolicy object
* [flux delete auto image-repository](flux_delete_auto_image-repository.md) - Delete an ImageRepository object * [flux delete auto image-repository](flux_delete_auto_image-repository.md) - Delete an ImageRepository object
* [flux delete auto image-update](flux_delete_auto_image-update.md) - Delete an ImageUpdateAutomation object

@ -0,0 +1,41 @@
## flux delete auto image-update
Delete an ImageUpdateAutomation object
### Synopsis
The delete auto image-update command deletes the given ImageUpdateAutomation from the cluster.
```
flux delete auto image-update [name] [flags]
```
### Examples
```
# Delete an image update automation
flux delete auto image-update latest-images
```
### Options
```
-h, --help help for image-update
```
### Options inherited from parent commands
```
--context string kubernetes context to use
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
-n, --namespace string the namespace scope for this operation (default "flux-system")
-s, --silent delete resource without asking for confirmation
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [flux delete auto](flux_delete_auto.md) - Delete automation objects

@ -28,4 +28,5 @@ The export auto sub-commands export automation object in YAML format.
* [flux export](flux_export.md) - Export resources in YAML format * [flux export](flux_export.md) - Export resources in YAML format
* [flux export auto image-policy](flux_export_auto_image-policy.md) - Export ImagePolicy resources in YAML format * [flux export auto image-policy](flux_export_auto_image-policy.md) - Export ImagePolicy resources in YAML format
* [flux export auto image-repository](flux_export_auto_image-repository.md) - Export ImageRepository resources in YAML format * [flux export auto image-repository](flux_export_auto_image-repository.md) - Export ImageRepository resources in YAML format
* [flux export auto image-update](flux_export_auto_image-update.md) - Export ImageUpdateAutomation resources in YAML format

@ -16,7 +16,7 @@ flux export auto image-policy [name] [flags]
# Export all ImagePolicy resources # Export all ImagePolicy resources
flux export auto image-policy --all > image-policies.yaml flux export auto image-policy --all > image-policies.yaml
# Export a Provider # Export a specific policy
flux export auto image-policy alpine1x > alpine1x.yaml flux export auto image-policy alpine1x > alpine1x.yaml
``` ```

@ -0,0 +1,44 @@
## flux export auto image-update
Export ImageUpdateAutomation resources in YAML format
### Synopsis
The export image-update command exports one or all ImageUpdateAutomation resources in YAML format.
```
flux export auto image-update [name] [flags]
```
### Examples
```
# Export all ImageUpdateAutomation resources
flux export auto image-update --all > updates.yaml
# Export a specific automation
flux export auto image-update latest-images > latest.yaml
```
### Options
```
-h, --help help for image-update
```
### Options inherited from parent commands
```
--all select all resources
--context string kubernetes context to use
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
-n, --namespace string the namespace scope for this operation (default "flux-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [flux export auto](flux_export_auto.md) - Export automation objects

@ -28,4 +28,5 @@ The get auto sub-commands print the statuses of the automation objects.
* [flux get](flux_get.md) - Get sources and resources * [flux get](flux_get.md) - Get sources and resources
* [flux get auto image-policy](flux_get_auto_image-policy.md) - Get ImagePolicy statuses * [flux get auto image-policy](flux_get_auto_image-policy.md) - Get ImagePolicy statuses
* [flux get auto image-repository](flux_get_auto_image-repository.md) - Get ImageRepository statuses * [flux get auto image-repository](flux_get_auto_image-repository.md) - Get ImageRepository statuses
* [flux get auto image-update](flux_get_auto_image-update.md) - Get ImageUpdateAutomation statuses

@ -0,0 +1,44 @@
## flux get auto image-update
Get ImageUpdateAutomation statuses
### Synopsis
The get auto image-update command prints the status of ImageUpdateAutomation objects.
```
flux get auto image-update [flags]
```
### Examples
```
# List all image update automation object and their status
flux get auto image-update
# List image update automations from all namespaces
flux get auto image-update --all-namespaces
```
### Options
```
-h, --help help for image-update
```
### Options inherited from parent commands
```
-A, --all-namespaces list the requested object(s) across all namespaces
--context string kubernetes context to use
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
-n, --namespace string the namespace scope for this operation (default "flux-system")
--timeout duration timeout for this operation (default 5m0s)
--verbose print generated objects
```
### SEE ALSO
* [flux get auto](flux_get_auto.md) - Get automation statuses
Loading…
Cancel
Save