Merge pull request #1116 from fluxcd/get-all-sources-images

Implement get all for sources and images
pull/1117/head
Stefan Prodan 4 years ago committed by GitHub
commit 3e85901f40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,9 +38,9 @@ mentioned in YAMLs in a git repository.`,
--git-repo-ref=flux-system \
--git-repo-path="./clusters/my-cluster" \
--checkout-branch=main \
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
# Configure image updates to push changes to a different branch, if the branch doesn't exists it will be created
flux create image update flux-system \
@ -48,9 +48,9 @@ mentioned in YAMLs in a git repository.`,
--git-repo-path="./clusters/my-cluster" \
--checkout-branch=main \
--push-branch=image-updates \
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
`,
RunE: createImageUpdateRun,
}

@ -18,7 +18,9 @@ package main
import (
"context"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
apimeta "k8s.io/apimachinery/pkg/api/meta"
@ -32,8 +34,8 @@ import (
var getCmd = &cobra.Command{
Use: "get",
Short: "Get sources and resources",
Long: "The get sub-commands print the statuses of sources and resources.",
Short: "Get the resources and their status",
Long: "The get sub-commands print the statuses of Flux resources.",
}
type GetFlags struct {
@ -50,7 +52,7 @@ func init() {
type summarisable interface {
listAdapter
summariseItem(i int, includeNamespace bool) []string
summariseItem(i int, includeNamespace bool, includeKind bool) []string
headers(includeNamespace bool) []string
}
@ -63,11 +65,17 @@ func statusAndMessage(conditions []metav1.Condition) (string, string) {
return string(metav1.ConditionFalse), "waiting to be reconciled"
}
func nameColumns(item named, includeNamespace bool) []string {
func nameColumns(item named, includeNamespace bool, includeKind bool) []string {
name := item.GetName()
if includeKind {
name = fmt.Sprintf("%s/%s",
strings.ToLower(item.GetObjectKind().GroupVersionKind().Kind),
item.GetName())
}
if includeNamespace {
return []string{item.GetNamespace(), item.GetName()}
return []string{item.GetNamespace(), name}
}
return []string{item.GetName()}
return []string{name}
}
var namespaceHeader = []string{"Namespace"}
@ -100,17 +108,25 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
return err
}
getAll := cmd.Use == "all"
if get.list.len() == 0 {
logger.Failuref("no %s objects found in %s namespace", get.kind, rootArgs.namespace)
if !getAll {
logger.Failuref("no %s objects found in %s namespace", get.kind, rootArgs.namespace)
}
return nil
}
header := get.list.headers(getArgs.allNamespaces)
var rows [][]string
for i := 0; i < get.list.len(); i++ {
row := get.list.summariseItem(i, getArgs.allNamespaces)
row := get.list.summariseItem(i, getArgs.allNamespaces, getAll)
rows = append(rows, row)
}
utils.PrintTable(os.Stdout, header, rows)
if getAll {
fmt.Println()
}
return nil
}

@ -42,11 +42,11 @@ func init() {
getCmd.AddCommand(getHelmReleaseCmd)
}
func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
revision := item.Status.LastAppliedRevision
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -0,0 +1,66 @@
/*
Copyright 2021 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 (
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
"github.com/spf13/cobra"
)
var getImageAllCmd = &cobra.Command{
Use: "all",
Short: "Get all image statuses",
Long: "The get image sub-commands print the statuses of all image objects.",
Example: ` # List all image objects in a namespace
flux get images all --namespace=flux-system
# List all image objects in all namespaces
flux get images all --all-namespaces
`,
RunE: func(cmd *cobra.Command, args []string) error {
c := getCommand{
apiType: imageRepositoryType,
list: imageRepositoryListAdapter{&imagev1.ImageRepositoryList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
c = getCommand{
apiType: imagePolicyType,
list: &imagePolicyListAdapter{&imagev1.ImagePolicyList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
c = getCommand{
apiType: imageUpdateAutomationType,
list: &imageUpdateAutomationListAdapter{&autov1.ImageUpdateAutomationList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
return nil
},
}
func init() {
getImageCmd.AddCommand(getImageAllCmd)
}

@ -42,10 +42,10 @@ func init() {
getImageCmd.AddCommand(getImagePolicyCmd)
}
func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (s imagePolicyListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace), status, msg, item.Status.LatestImage)
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, item.Status.LatestImage)
}
func (s imagePolicyListAdapter) headers(includeNamespace bool) []string {

@ -46,14 +46,14 @@ func init() {
getImageCmd.AddCommand(getImageRepositoryCmd)
}
func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (s imageRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := s.Items[i]
status, msg := statusAndMessage(item.Status.Conditions)
var lastScan string
if item.Status.LastScanResult != nil {
lastScan = item.Status.LastScanResult.ScanTime.Time.Format(time.RFC3339)
}
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, lastScan, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -46,14 +46,14 @@ func init() {
getImageCmd.AddCommand(getImageUpdateCmd)
}
func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (s imageUpdateAutomationListAdapter) summariseItem(i int, includeNamespace bool, includeKind 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)))
return append(nameColumns(&item, includeNamespace, includeKind), status, msg, lastRun, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}
func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []string {

@ -42,11 +42,11 @@ func init() {
getCmd.AddCommand(getKsCmd)
}
func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
revision := item.Status.LastAppliedRevision
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -0,0 +1,73 @@
/*
Copyright 2021 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 (
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
"github.com/spf13/cobra"
)
var getSourceAllCmd = &cobra.Command{
Use: "all",
Short: "Get all source statuses",
Long: "The get sources all command print the statuses of all sources.",
Example: ` # List all sources in a namespace
flux get sources all --namespace=flux-system
# List all sources in all namespaces
flux get sources all --all-namespaces
`,
RunE: func(cmd *cobra.Command, args []string) error {
c := getCommand{
apiType: bucketType,
list: &bucketListAdapter{&sourcev1.BucketList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
c = getCommand{
apiType: gitRepositoryType,
list: &gitRepositoryListAdapter{&sourcev1.GitRepositoryList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
c = getCommand{
apiType: helmRepositoryType,
list: &helmRepositoryListAdapter{&sourcev1.HelmRepositoryList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
c = getCommand{
apiType: helmChartType,
list: &helmChartListAdapter{&sourcev1.HelmChartList{}},
}
if err := c.run(cmd, args); err != nil {
logger.Failuref(err.Error())
}
return nil
},
}
func init() {
getSourceCmd.AddCommand(getSourceAllCmd)
}

@ -44,14 +44,14 @@ func init() {
getSourceCmd.AddCommand(getSourceBucketCmd)
}
func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (a *bucketListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
var revision string
if item.GetArtifact() != nil {
revision = item.GetArtifact().Revision
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -44,14 +44,14 @@ func init() {
getSourceCmd.AddCommand(getSourceHelmChartCmd)
}
func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (a *helmChartListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
var revision string
if item.GetArtifact() != nil {
revision = item.GetArtifact().Revision
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -44,14 +44,14 @@ func init() {
getSourceCmd.AddCommand(getSourceGitCmd)
}
func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
var revision string
if item.GetArtifact() != nil {
revision = item.GetArtifact().Revision
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -44,14 +44,14 @@ func init() {
getSourceCmd.AddCommand(getSourceHelmCmd)
}
func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool) []string {
func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
var revision string
if item.GetArtifact() != nil {
revision = item.GetArtifact().Revision
}
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace),
return append(nameColumns(&item, includeNamespace, includeKind),
status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend)))
}

@ -17,6 +17,7 @@ limitations under the License.
package main
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
)
@ -62,6 +63,7 @@ func (c universalAdapter) asClientObject() client.Object {
type named interface {
GetName() string
GetNamespace() string
GetObjectKind() schema.ObjectKind
SetName(string)
SetNamespace(string)
}

@ -70,7 +70,7 @@ func (a helmChartAdapter) asClientObject() client.Object {
return a.HelmChart
}
// sourcev1.ImagePolicyList
// sourcev1.HelmChartList
type helmChartListAdapter struct {
*sourcev1.HelmChartList

@ -83,7 +83,7 @@ Command line utility for assembling Kubernetes CD pipelines the GitOps way.
* [flux create](flux_create.md) - Create or update sources and resources
* [flux delete](flux_delete.md) - Delete sources and resources
* [flux export](flux_export.md) - Export resources in YAML format
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status
* [flux install](flux_install.md) - Install or upgrade Flux
* [flux logs](flux_logs.md) - Display formatted logs for Flux components
* [flux reconcile](flux_reconcile.md) - Reconcile sources and resources

@ -20,9 +20,9 @@ flux create image update [name] [flags]
--git-repo-ref=flux-system \
--git-repo-path="./clusters/my-cluster" \
--checkout-branch=main \
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
# Configure image updates to push changes to a different branch, if the branch doesn't exists it will be created
flux create image update flux-system \
@ -30,9 +30,9 @@ flux create image update [name] [flags]
--git-repo-path="./clusters/my-cluster" \
--checkout-branch=main \
--push-branch=image-updates \
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
--author-name=flux \
--author-email=flux@example.com \
--commit-template="{{range .Updated.Images}}{{println .}}{{end}}"
```

@ -1,10 +1,10 @@
## flux get
Get sources and resources
Get the resources and their status
### Synopsis
The get sub-commands print the statuses of sources and resources.
The get sub-commands print the statuses of Flux resources.
### Options

@ -37,5 +37,5 @@ flux get alert-providers [flags]
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status

@ -37,5 +37,5 @@ flux get alerts [flags]
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status

@ -37,5 +37,5 @@ flux get helmreleases [flags]
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status

@ -25,7 +25,8 @@ The get image sub-commands print the status of image automation objects.
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status
* [flux get images all](flux_get_images_all.md) - Get all image statuses
* [flux get images policy](flux_get_images_policy.md) - Get ImagePolicy status
* [flux get images repository](flux_get_images_repository.md) - Get ImageRepository status
* [flux get images update](flux_get_images_update.md) - Get ImageUpdateAutomation status

@ -0,0 +1,44 @@
## flux get images all
Get all image statuses
### Synopsis
The get image sub-commands print the statuses of all image objects.
```
flux get images all [flags]
```
### Examples
```
# List all image objects in a namespace
flux get images all --namespace=flux-system
# List all image objects in all namespaces
flux get images all --all-namespaces
```
### Options
```
-h, --help help for all
```
### 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 images](flux_get_images.md) - Get image automation object status

@ -37,5 +37,5 @@ flux get kustomizations [flags]
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status

@ -37,5 +37,5 @@ flux get receivers [flags]
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status

@ -25,7 +25,8 @@ The get source sub-commands print the statuses of the sources.
### SEE ALSO
* [flux get](flux_get.md) - Get sources and resources
* [flux get](flux_get.md) - Get the resources and their status
* [flux get sources all](flux_get_sources_all.md) - Get all source statuses
* [flux get sources bucket](flux_get_sources_bucket.md) - Get Bucket source statuses
* [flux get sources chart](flux_get_sources_chart.md) - Get HelmChart statuses
* [flux get sources git](flux_get_sources_git.md) - Get GitRepository source statuses

@ -0,0 +1,44 @@
## flux get sources all
Get all source statuses
### Synopsis
The get sources all command print the statuses of all sources.
```
flux get sources all [flags]
```
### Examples
```
# List all sources in a namespace
flux get sources all --namespace=flux-system
# List all sources in all namespaces
flux get sources all --all-namespaces
```
### Options
```
-h, --help help for all
```
### 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 sources](flux_get_sources.md) - Get source statuses

@ -148,6 +148,7 @@ nav:
- Get kustomizations: cmd/flux_get_kustomizations.md
- Get helmreleases: cmd/flux_get_helmreleases.md
- Get sources: cmd/flux_get_sources.md
- Get sources all: cmd/flux_get_sources_all.md
- Get sources git: cmd/flux_get_sources_git.md
- Get sources helm: cmd/flux_get_sources_helm.md
- Get sources chart: cmd/flux_get_sources_chart.md
@ -157,6 +158,7 @@ nav:
- Get alert providers: cmd/flux_get_alert-providers.md
- Get receivers: cmd/flux_get_receivers.md
- Get images: cmd/flux_get_images.md
- Get images all: cmd/flux_get_images_all.md
- Get images policy: cmd/flux_get_images_policy.md
- Get images repository: cmd/flux_get_images_repository.md
- Get images update: cmd/flux_get_images_update.md

Loading…
Cancel
Save