Skip to content

Commit

Permalink
feat: kind-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Jan 5, 2023
1 parent 5a2b863 commit 6abf651
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
interval := flag.String("interval", "5s", "Interval between status checks")
retryLimit := flag.Int64("retry-limit", 6, "Retry limit for deployments and statefulsets, default 6, -1 to disable")
pendingDeadLineSeconds := flag.Int("pending-deadline", 180, "Pending deadLine in seconds, default 180, -1 to disable")
kindFilter := flag.String("kind-filter", "", "Kind filter, one of deployment, job or statefulset")

ignoreSecretNotFound := flag.Bool("ignore-secret-not-found", false, "Ignore secret not found error")

Expand All @@ -39,6 +40,7 @@ func main() {
IgnoreSecretNotFound: *ignoreSecretNotFound,
RetryLimit: int32(*retryLimit),
PendingDeadLineSeconds: *pendingDeadLineSeconds,
KindFilter: config.KindFilter(*kindFilter),
}

clientset := makeClientset(*kubeconfig, *kubecontext)
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package config

type KindFilter string

const (
NoKindFilter KindFilter = ""
DeploymentKindFilter KindFilter = "deployment"
JobKindFilter KindFilter = "job"
StatefulsetKindFilter KindFilter = "statefulset"
)

type Options struct {
IgnoreSecretNotFound bool
RetryLimit int32
PendingDeadLineSeconds int
KindFilter KindFilter
}
31 changes: 22 additions & 9 deletions pkg/status/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@ package status
import (
"github.com/SocialGouv/rollout-status/pkg/client"
"github.com/SocialGouv/rollout-status/pkg/config"
v1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
)

func TestRollout(wrapper client.Kubernetes, namespace, selector string, options *config.Options) RolloutStatus {
deployments, err := wrapper.ListAppsV1Deployments(namespace, selector)
if err != nil {
return RolloutFatal(err)
var err error

var deployments *v1.DeploymentList
if options.KindFilter == config.NoKindFilter || options.KindFilter == config.DeploymentKindFilter {
deployments, err = wrapper.ListAppsV1Deployments(namespace, selector)
if err != nil {
return RolloutFatal(err)
}
}

statefulsets, err := wrapper.ListAppsV1StatefulSets(namespace, selector)
if err != nil {
return RolloutFatal(err)
var statefulsets *v1.StatefulSetList
if options.KindFilter == config.NoKindFilter || options.KindFilter == config.StatefulsetKindFilter {
statefulsets, err = wrapper.ListAppsV1StatefulSets(namespace, selector)
if err != nil {
return RolloutFatal(err)
}
}

jobs, err := wrapper.ListBatchV1Jobs(namespace, selector)
if err != nil {
return RolloutFatal(err)
var jobs *batchv1.JobList
if options.KindFilter == config.NoKindFilter || options.KindFilter == config.JobKindFilter {
jobs, err = wrapper.ListBatchV1Jobs(namespace, selector)
if err != nil {
return RolloutFatal(err)
}
}

if (deployments == nil || len(deployments.Items) == 0) && (statefulsets == nil || len(statefulsets.Items) == 0) && (jobs == nil || len(jobs.Items) == 0) {
Expand Down

0 comments on commit 6abf651

Please sign in to comment.