-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Job CLI deploy/list/export/remove #119
Conversation
b960a27
to
0b5fb40
Compare
adds unit tests fixes job templates; fixes unit tests adds job cli tests make install includes job add job help test troubleshoot cli tests fix job help test chasing missing framework modify job create/update in deploy; chase cli test errors mv job tests to new file try go integration tests add longer wait for framework list make job cluster-level; fix up tests reset app tests reset app tests clean up tests more; fix job.deploy usage rm extra assertion
@@ -4,6 +4,7 @@ | |||
resources: | |||
- bases/theketch.io_apps.yaml | |||
- bases/theketch.io_frameworks.yaml | |||
- bases/theketch.io_jobs.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to add this during the job CRD PR #116. Makes make install
install job crd.
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// JobSpec defines the desired state of Job | ||
type JobSpec struct { | ||
Version string `json:"version"` | ||
Version string `json:"version,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more potentially empty fields.
@@ -45,6 +45,8 @@ type JobStatus struct { | |||
|
|||
//+kubebuilder:object:root=true | |||
//+kubebuilder:subresource:status | |||
// +kubebuilder:resource:scope=Cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think job scope should be cluster level, like app. Missed this in in the job CRD PR #116.
@@ -7,16 +7,16 @@ metadata: | |||
name: {{ $.Values.job.name }} | |||
spec: | |||
{{- if $.Values.job.parallelism }} | |||
{{ $.Values.job.parallelism | toYaml | indent 4 }} | |||
parallelism: {{ $.Values.job.parallelism }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I botched a few template fields in the job CRD PR #116. Fixed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks awesome
cmd/ketch/job_deploy.go
Outdated
} | ||
|
||
var job ketchv1.Job | ||
err = cfg.Client().Get(ctx, types.NamespacedName{Name: spec.Name}, &job) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about using
import (
ctrl "sigs.k8s.io/controller-runtime"
)
ctrl.CreateOrUdate()
https://github.com/kubernetes-sigs/controller-runtime/blob/master/alias.go#L115
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I didn't even know it existed...until now.
cmd/ketch/job_deploy_test.go
Outdated
require.NotNil(t, err) | ||
require.Equal(t, tt.wantErr, err.Error()) | ||
return | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use else
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Thanks for catching all these.
cmd/ketch/job_export.go
Outdated
if err := cfg.Client().Get(ctx, types.NamespacedName{Name: options.name}, &job); err != nil { | ||
return err | ||
} | ||
if options.filename != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use this pattern multiple times, how about having an independent function for exporting
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Refactored into the cmd/output package for the 3 export
commands to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked about the whole piece of code
if options.filename != "" {
f, err := output.GetOutputFile(options.filename)
if err != nil {
return err
}
defer f.Close()
out = f
}
b, err := yaml.Marshal(job.Spec)
if err != nil {
return err
}
_, err = out.Write(b)
but it doesn't really matter, it is up to you
cmd/ketch/job_list.go
Outdated
func jobListNames(cfg config, nameFilter ...string) ([]string, error) { | ||
jobs := ketchv1.JobList{} | ||
if err := cfg.Client().List(context.TODO(), &jobs); err != nil { | ||
return nil, fmt.Errorf("failed to list apps: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be failed to list jobs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. It's possible I was copy/pasting.
cmd/ketch/job_remove_test.go
Outdated
require.NotNil(t, err) | ||
require.Equal(t, tt.wantErr, err.Error()) | ||
return | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to have else
statement
|
||
# To run locally: | ||
# export KETCH_EXECUTABLE_PATH=<location of ketch binary> | ||
# assure you have a kubernetes cluster running w/ traefik, cert manager, etc. (see ketch getting started docs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cmd/ketch/job_export_test.go
Outdated
require.NotNil(t, err) | ||
require.Equal(t, tt.wantErr, err.Error()) | ||
return | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use else
…utputFile func; removes unneeded 'else' clauses
cmd/ketch/job_export.go
Outdated
if err := cfg.Client().Get(ctx, types.NamespacedName{Name: options.name}, &job); err != nil { | ||
return err | ||
} | ||
if options.filename != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked about the whole piece of code
if options.filename != "" {
f, err := output.GetOutputFile(options.filename)
if err != nil {
return err
}
defer f.Close()
out = f
}
b, err := yaml.Marshal(job.Spec)
if err != nil {
return err
}
_, err = out.Write(b)
but it doesn't really matter, it is up to you
Haha @aleksej-paschenko. Got it. It went right over my head. Refactored the whole block. |
Description
Adds CLI commands
job deploy
,job list
,job export
,job remove
. Job deploy only implements yaml file deployments. Spec here. Makes version, policy, and description fields optional.I also found some small fixes that were needed for the Job CRD, noted in comments.
Try it:
make install ketch manager
./bin/manager --enable-leader-election=false --disable-webhooks
(assuming you're not deploying)./bin/ketch framework add fw
./bin/ketch job deploy job.yaml
k get jobs -n ketch-fw
k get pods -n ketch-fw
k logs <pod> - n ketch-fw pi
./bin/ketch job export myjob
./bin/ketch job list
./bin/ketch job remove myjob
example job.yaml:
Fixes # 1542
Type of change
Testing
Documentation
Final Checklist:
Additional Information (omit if empty)
Please include anything else relevant to this PR that may be useful to know.