Skip to content

Commit

Permalink
Fix/fix linter errors (#34)
Browse files Browse the repository at this point in the history
* (PXP-10137): log errors, use 'Fprint' instead of 'Fprintf'.

* (PXP-10137): merge declaration and initialization of 'batchJob'.

* (PXP-10137): specify go version to match go.mod.
  • Loading branch information
george42-ctds committed Jul 21, 2022
1 parent 11d6baf commit b20dd7e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/golang-ci-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
ci:
runs-on: ubuntu-latest
env:
GO_VERSION: "1.17"
COVERAGE_PROFILE_OUTPUT_LOCATION: "./profile.cov"
steps:
- name: Checkout code / lint code / install dependencies for goveralls / run tests
Expand Down
13 changes: 10 additions & 3 deletions handlers/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,9 @@ func createK8sJob(currentAction string, inputData string, accessFormat string, a
var volumeMounts []k8sv1.VolumeMount
volumeMounts = append(volumeMounts, conf.Container.VolumesMounts...)

var batchJob *batchv1.Job

// For an example of how to create jobs, see this file:
// https://github.com/pachyderm/pachyderm/blob/805e63/src/server/pps/server/api_server.go#L2320-L2345
batchJob = &batchv1.Job{
var batchJob *batchv1.Job = &batchv1.Job{
TypeMeta: metav1.TypeMeta{
Kind: "Job",
APIVersion: "v1",
Expand Down Expand Up @@ -277,7 +275,13 @@ func getPodMatchingJob(jobname string) *k8sv1.Pod {
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Errorf("Failed to create clientset.\nError: %s", err.Error())
}
pods, err := clientset.CoreV1().Pods(kubectlNamespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
log.Errorf("Failed to create pods.\nError: %s", err.Error())
}
for _, pod := range pods.Items {
if strings.HasPrefix(pod.Name, jobname) {
return &pod
Expand All @@ -304,6 +308,9 @@ func getJobLogs(jobid string, username string) (*JobOutput, error) {
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Errorf("Failed to create clientset.\nError: %s", err.Error())
}
podLogOptions := k8sv1.PodLogOptions{}
req := clientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOptions)
podLogs, err := req.Stream(context.TODO())
Expand Down
4 changes: 2 additions & 2 deletions handlers/sower.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func dispatch(w http.ResponseWriter, r *http.Request) {
return
}

fmt.Fprintf(w, string(out))
fmt.Fprint(w, string(out))
}

func status(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -186,7 +186,7 @@ func list(w http.ResponseWriter, r *http.Request) {
return
}

fmt.Fprintf(w, string(out))
fmt.Fprint(w, string(out))
}

func getBearerToken(r *http.Request) *string {
Expand Down
4 changes: 2 additions & 2 deletions handlers/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func RegisterSystem() {
}

func systemStatus(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Healthy")
fmt.Fprint(w, "Healthy")
}

func systemVersion(w http.ResponseWriter, r *http.Request) {
Expand All @@ -30,5 +30,5 @@ func systemVersion(w http.ResponseWriter, r *http.Request) {
return
}

fmt.Fprintf(w, string(out))
fmt.Fprint(w, string(out))
}

0 comments on commit b20dd7e

Please sign in to comment.