Skip to content
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

Merged
merged 3 commits into from
Jul 23, 2021
Merged

Job CLI deploy/list/export/remove #119

merged 3 commits into from
Jul 23, 2021

Conversation

stinkyfingers
Copy link
Contributor

@stinkyfingers stinkyfingers commented Jul 21, 2021

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:

name: myjob
version: v1
type: Job
framework: fw
description: "cli test job"
containers:
  - name: pi
    image: perl
    command:
      - "perl"
      - "-Mbignum=bpi"
      - "-wle"
      - "print bpi(2000)"

Fixes # 1542

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Chore (documentation addition or typo, file relocation)

Testing

  • New tests were added with this PR that prove my fix is effective or that my feature works (describe below this bullet)
  • This change requires no testing (i.e. documentation update)

Documentation

  • All added public packages, funcs, and types have been documented with doc comments
  • I have commented my code, particularly in hard-to-understand areas

Final Checklist:

  • I followed standard GitHub flow guidelines
  • I have performed a self-review of my own code
  • My changes generate no new warnings

Additional Information (omit if empty)

Please include anything else relevant to this PR that may be useful to know.

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
Copy link
Contributor Author

@stinkyfingers stinkyfingers Jul 23, 2021

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"`
Copy link
Contributor Author

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
Copy link
Contributor Author

@stinkyfingers stinkyfingers Jul 23, 2021

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 }}
Copy link
Contributor Author

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.

Copy link
Contributor

@aleksej-paschenko aleksej-paschenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks awesome

}

var job ketchv1.Job
err = cfg.Client().Get(ctx, types.NamespacedName{Name: spec.Name}, &job)
Copy link
Contributor

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
?

Copy link
Contributor Author

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.

require.NotNil(t, err)
require.Equal(t, tt.wantErr, err.Error())
return
} else {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

if err := cfg.Client().Get(ctx, types.NamespacedName{Name: options.name}, &job); err != nil {
return err
}
if options.filename != "" {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

require.NotNil(t, err)
require.Equal(t, tt.wantErr, err.Error())
return
} else {
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

require.NotNil(t, err)
require.Equal(t, tt.wantErr, err.Error())
return
} else {
Copy link
Contributor

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
if err := cfg.Client().Get(ctx, types.NamespacedName{Name: options.name}, &job); err != nil {
return err
}
if options.filename != "" {
Copy link
Contributor

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

@stinkyfingers
Copy link
Contributor Author

Haha @aleksej-paschenko. Got it. It went right over my head. Refactored the whole block.

@stinkyfingers stinkyfingers merged commit 9d1a47d into main Jul 23, 2021
@stinkyfingers stinkyfingers deleted the jds/1542 branch July 23, 2021 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants