Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ae39d5a0a | ||
|
|
d8911e0c77 | ||
|
|
1be006a45f | ||
|
|
b95e75ddb4 | ||
|
|
15a5f75fe7 | ||
|
|
b01e27f50f | ||
|
|
b1a9583262 | ||
|
|
dd5e6377f8 | ||
|
|
fcb73554c9 | ||
|
|
5c4b3d1080 | ||
|
|
c98cd10621 |
@@ -39,7 +39,9 @@ var getCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
type GetFlags struct {
|
||||
allNamespaces bool
|
||||
allNamespaces bool
|
||||
noHeader bool
|
||||
statusSelector string
|
||||
}
|
||||
|
||||
var getArgs GetFlags
|
||||
@@ -47,6 +49,9 @@ var getArgs GetFlags
|
||||
func init() {
|
||||
getCmd.PersistentFlags().BoolVarP(&getArgs.allNamespaces, "all-namespaces", "A", false,
|
||||
"list the requested object(s) across all namespaces")
|
||||
getCmd.PersistentFlags().BoolVarP(&getArgs.noHeader, "no-header", "", false, "skip the header when printing the results")
|
||||
getCmd.PersistentFlags().StringVar(&getArgs.statusSelector, "status-selector", "",
|
||||
"specify the status condition name and the desired state to filter the get result, e.g. ready=false")
|
||||
rootCmd.AddCommand(getCmd)
|
||||
}
|
||||
|
||||
@@ -54,6 +59,7 @@ type summarisable interface {
|
||||
listAdapter
|
||||
summariseItem(i int, includeNamespace bool, includeKind bool) []string
|
||||
headers(includeNamespace bool) []string
|
||||
statusSelectorMatches(i int, conditionType, conditionStatus string) bool
|
||||
}
|
||||
|
||||
// --- these help with implementations of summarisable
|
||||
@@ -65,6 +71,20 @@ func statusAndMessage(conditions []metav1.Condition) (string, string) {
|
||||
return string(metav1.ConditionFalse), "waiting to be reconciled"
|
||||
}
|
||||
|
||||
func statusMatches(conditionType, conditionStatus string, conditions []metav1.Condition) bool {
|
||||
// we don't use apimeta.FindStatusCondition because we'd like to use EqualFold to compare two strings
|
||||
var c *metav1.Condition
|
||||
for i := range conditions {
|
||||
if strings.EqualFold(conditions[i].Type, conditionType) {
|
||||
c = &conditions[i]
|
||||
}
|
||||
}
|
||||
if c != nil {
|
||||
return strings.EqualFold(string(c.Status), conditionStatus)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func nameColumns(item named, includeNamespace bool, includeKind bool) []string {
|
||||
name := item.GetName()
|
||||
if includeKind {
|
||||
@@ -117,11 +137,27 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
header := get.list.headers(getArgs.allNamespaces)
|
||||
var header []string
|
||||
if !getArgs.noHeader {
|
||||
header = get.list.headers(getArgs.allNamespaces)
|
||||
}
|
||||
noFilter := true
|
||||
var conditionType, conditionStatus string
|
||||
if getArgs.statusSelector != "" {
|
||||
parts := strings.SplitN(getArgs.statusSelector, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
return fmt.Errorf("expected status selector in type=status format, but found: %s", getArgs.statusSelector)
|
||||
}
|
||||
conditionType = parts[0]
|
||||
conditionStatus = parts[1]
|
||||
noFilter = false
|
||||
}
|
||||
var rows [][]string
|
||||
for i := 0; i < get.list.len(); i++ {
|
||||
row := get.list.summariseItem(i, getArgs.allNamespaces, getAll)
|
||||
rows = append(rows, row)
|
||||
if noFilter || get.list.statusSelectorMatches(i, conditionType, conditionStatus) {
|
||||
row := get.list.summariseItem(i, getArgs.allNamespaces, getAll)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
}
|
||||
utils.PrintTable(os.Stdout, header, rows)
|
||||
|
||||
|
||||
@@ -55,3 +55,8 @@ func (s alertListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (s alertListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := s.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -52,3 +52,8 @@ func (s alertProviderListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (s alertProviderListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := s.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -56,3 +56,8 @@ func (a helmReleaseListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (a helmReleaseListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -54,3 +54,8 @@ func (s imagePolicyListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (s imagePolicyListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := s.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -63,3 +63,8 @@ func (s imageRepositoryListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (s imageRepositoryListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := s.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -62,3 +62,8 @@ func (s imageUpdateAutomationListAdapter) headers(includeNamespace bool) []strin
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (s imageUpdateAutomationListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := s.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -57,3 +57,8 @@ func (a kustomizationListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (a kustomizationListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -55,3 +55,8 @@ func (s receiverListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (s receiverListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := s.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -62,3 +62,8 @@ func (a bucketListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (a bucketListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -62,3 +62,8 @@ func (a helmChartListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (a helmChartListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -62,3 +62,8 @@ func (a gitRepositoryListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (a gitRepositoryListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
@@ -62,3 +62,8 @@ func (a helmRepositoryListAdapter) headers(includeNamespace bool) []string {
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func (a helmRepositoryListAdapter) statusSelectorMatches(i int, conditionType, conditionStatus string) bool {
|
||||
item := a.Items[i]
|
||||
return statusMatches(conditionType, conditionStatus, item.Status.Conditions)
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -9,7 +9,7 @@ require (
|
||||
github.com/fluxcd/helm-controller/api v0.11.1
|
||||
github.com/fluxcd/image-automation-controller/api v0.14.0
|
||||
github.com/fluxcd/image-reflector-controller/api v0.11.0
|
||||
github.com/fluxcd/kustomize-controller/api v0.13.1
|
||||
github.com/fluxcd/kustomize-controller/api v0.13.2
|
||||
github.com/fluxcd/notification-controller/api v0.15.0
|
||||
github.com/fluxcd/pkg/apis/meta v0.10.0
|
||||
github.com/fluxcd/pkg/runtime v0.12.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -207,8 +207,8 @@ github.com/fluxcd/image-automation-controller/api v0.14.0 h1:8/mv1KUaXDzXq+TSJWL
|
||||
github.com/fluxcd/image-automation-controller/api v0.14.0/go.mod h1:WDBKSufHazCf065F9qPWtVPUN8kU4MdM5rVC1MoZtpk=
|
||||
github.com/fluxcd/image-reflector-controller/api v0.11.0 h1:Pz9GuUQvmJO5nJPEtGBRQnIHvcY+ITqI4LdSiW11toE=
|
||||
github.com/fluxcd/image-reflector-controller/api v0.11.0/go.mod h1:X4qZ11pfA5w1ajbkYbWmQ3hBW3gzCyIjhU87AvV6o2A=
|
||||
github.com/fluxcd/kustomize-controller/api v0.13.1 h1:BMSa/Z8sKeUUMSIPcpttoWB443AzHyJdxMtKKg4Adc8=
|
||||
github.com/fluxcd/kustomize-controller/api v0.13.1/go.mod h1:hh8LG9D89cLeXJJv3z78aoFh03X9hn2FSiibofX3UBk=
|
||||
github.com/fluxcd/kustomize-controller/api v0.13.2 h1:Dd+gryMtV1J6TuFvbHj50VFauUNOtC3Uowa5yxgZ+l0=
|
||||
github.com/fluxcd/kustomize-controller/api v0.13.2/go.mod h1:hh8LG9D89cLeXJJv3z78aoFh03X9hn2FSiibofX3UBk=
|
||||
github.com/fluxcd/notification-controller/api v0.15.0 h1:NWBnggAd07vQP90HwRZHv+z4hzE/sC03/knLrw2OJdY=
|
||||
github.com/fluxcd/notification-controller/api v0.15.0/go.mod h1:fh5AgXtcceoTpqVTHrISIVLcb3Z/qK8F9cysyhuAkfI=
|
||||
github.com/fluxcd/pkg/apis/kustomize v0.1.0/go.mod h1:gEl+W5cVykCC3RfrCaqe+Pz+j4lKl2aeR4dxsom/zII=
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.1/kustomize-controller.crds.yaml
|
||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.1/kustomize-controller.deployment.yaml
|
||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.2/kustomize-controller.crds.yaml
|
||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.2/kustomize-controller.deployment.yaml
|
||||
- account.yaml
|
||||
patchesJson6902:
|
||||
- target:
|
||||
|
||||
@@ -2,7 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- https://github.com/fluxcd/source-controller/releases/download/v0.15.3/source-controller.crds.yaml
|
||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.1/kustomize-controller.crds.yaml
|
||||
- https://github.com/fluxcd/kustomize-controller/releases/download/v0.13.2/kustomize-controller.crds.yaml
|
||||
- https://github.com/fluxcd/helm-controller/releases/download/v0.11.1/helm-controller.crds.yaml
|
||||
- https://github.com/fluxcd/notification-controller/releases/download/v0.15.0/notification-controller.crds.yaml
|
||||
- https://github.com/fluxcd/image-reflector-controller/releases/download/v0.11.0/image-reflector-controller.crds.yaml
|
||||
|
||||
@@ -547,7 +547,7 @@
|
||||
{
|
||||
"expr": "rate(process_cpu_seconds_total{namespace=\"$namespace\",pod=~\".*-controller-.*\"}[1m])",
|
||||
"interval": "",
|
||||
"legendFormat": "{{kubernetes_pod_name}}",
|
||||
"legendFormat": "{{pod}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
@@ -643,7 +643,7 @@
|
||||
"expr": "rate(go_memstats_alloc_bytes_total{namespace=\"$namespace\",pod=~\".*-controller-.*\"}[1m])",
|
||||
"hide": false,
|
||||
"interval": "",
|
||||
"legendFormat": "{{kubernetes_pod_name}}",
|
||||
"legendFormat": "{{pod}}",
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -21,4 +21,4 @@ spec:
|
||||
- image-automation-controller
|
||||
- image-reflector-controller
|
||||
podMetricsEndpoints:
|
||||
- targetPort: http-prom
|
||||
- port: http-prom
|
||||
|
||||
Reference in New Issue
Block a user