Skip to content

Commit

Permalink
Add job filter
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossg authored and boz committed Jan 21, 2020
1 parent 1b5394f commit 01cbb7a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Flag | Selection
`--rc NAME` | match pods belonging to the given replication controller
`--rs NAME` | match pods belonging to the given replica set
`-d, --deploy NAME` | match pods belonging to the given deployment
`-j, --job NAME` | match pods belonging to the given job
`--node NODE-NAME` | match pods running on the given node
`--ing NAME` | match pods belonging to services targeted by the given ingress
`-c, --containers CONTAINER-NAME` | restrict which containers logs are shown for
Expand Down
5 changes: 5 additions & 0 deletions cmd/kail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
flagRs = kingpin.Flag("rs", "replica set").PlaceHolder("NAME").Strings()
flagDs = kingpin.Flag("ds", "daemonset").PlaceHolder("NAME").Strings()
flagDeployment = kingpin.Flag("deploy", "deployment").Short('d').PlaceHolder("NAME").Strings()
flagJob = kingpin.Flag("job", "job").Short('j').PlaceHolder("NAME").Strings()
flagNode = kingpin.Flag("node", "node").PlaceHolder("NAME").Strings()
flagIng = kingpin.Flag("ing", "ingress").PlaceHolder("NAME").Strings()

Expand Down Expand Up @@ -253,6 +254,10 @@ func createDSBuilder() kail.DSBuilder {
dsb = dsb.WithDeployment(ids...)
}

if ids := parseIds("job", *flagJob); len(ids) > 0 {
dsb = dsb.WithJob(ids...)
}

if ids := parseIds("ing", *flagIng); len(ids) > 0 {
dsb = dsb.WithIngress(ids...)
}
Expand Down
3 changes: 3 additions & 0 deletions ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/boz/kcache/types/daemonset"
"github.com/boz/kcache/types/deployment"
"github.com/boz/kcache/types/ingress"
"github.com/boz/kcache/types/job"
"github.com/boz/kcache/types/node"
"github.com/boz/kcache/types/pod"
"github.com/boz/kcache/types/replicaset"
Expand All @@ -29,6 +30,7 @@ type datastore struct {
rssBase replicaset.Controller
dssBase daemonset.Controller
deploymentsBase deployment.Controller
jobsBase job.Controller
ingressesBase ingress.Controller

pods pod.Controller
Expand All @@ -38,6 +40,7 @@ type datastore struct {
rss replicaset.Controller
dss daemonset.Controller
deployments deployment.Controller
jobs job.Controller
ingresses ingress.Controller

readych chan struct{}
Expand Down
28 changes: 28 additions & 0 deletions ds_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kail

import (
"context"
"github.com/boz/kcache/types/job"

logutil "github.com/boz/go-logutil"
"github.com/boz/kcache/filter"
Expand Down Expand Up @@ -31,6 +32,7 @@ type DSBuilder interface {
WithRS(id ...nsname.NSName) DSBuilder
WithDS(id ...nsname.NSName) DSBuilder
WithDeployment(id ...nsname.NSName) DSBuilder
WithJob(id ...nsname.NSName) DSBuilder
WithIngress(id ...nsname.NSName) DSBuilder

Create(ctx context.Context, cs kubernetes.Interface) (DS, error)
Expand All @@ -52,6 +54,7 @@ type dsBuilder struct {
rss []nsname.NSName
dss []nsname.NSName
deployments []nsname.NSName
jobs []nsname.NSName
ingresses []nsname.NSName
}

Expand Down Expand Up @@ -110,6 +113,11 @@ func (b *dsBuilder) WithDeployment(id ...nsname.NSName) DSBuilder {
return b
}

func (b *dsBuilder) WithJob(id ...nsname.NSName) DSBuilder {
b.jobs = append(b.jobs, id...)
return b
}

func (b *dsBuilder) WithIngress(id ...nsname.NSName) DSBuilder {
b.ingresses = append(b.ingresses, id...)
return b
Expand Down Expand Up @@ -321,6 +329,26 @@ func (b *dsBuilder) Create(ctx context.Context, cs kubernetes.Interface) (DS, er
}
}

if len(b.jobs) != 0 {
ds.jobsBase, err = job.NewController(ctx, log, cs, namespace)
if err != nil {
ds.closeAll()
return nil, log.Err(err, "job base controller")
}

ds.jobs, err = ds.jobsBase.CloneWithFilter(filter.NSName(b.jobs...))
if err != nil {
ds.closeAll()
return nil, log.Err(err, "job controller")
}

ds.pods, err = join.JobPods(ctx, ds.jobs, ds.pods)
if err != nil {
ds.closeAll()
return nil, log.Err(err, "job join")
}
}

if len(b.ingresses) != 0 {
ds.ingressesBase, err = ingress.NewController(ctx, log, cs, namespace)
if err != nil {
Expand Down

0 comments on commit 01cbb7a

Please sign in to comment.