mirror of https://github.com/fluxcd/flux2.git
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
parent
433628791b
commit
f316aff2d3
@ -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
|
||||||
|
}
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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…
Reference in New Issue