forked from jupyterhub/zero-to-jupyterhub-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utilize k8s-api for daemonset status instead of listing pods
- Loading branch information
1 parent
f4ebfab
commit 01eac78
Showing
11 changed files
with
119 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
// Partial structure of a Kubernetes DaemonSet object | ||
// Only contains fields we will actively be using, to make JSON parsing nicer | ||
type DaemonSet struct { | ||
Kind string `json:"kind"` | ||
Status struct { | ||
DesiredNumberScheduled int `json:"desiredNumberScheduled"` | ||
NumberReady int `json:"numberReady"` | ||
} `json:"status"` | ||
} | ||
|
||
// Return a *DaemonSet and the relevant state its in | ||
func getDaemonSet(transportPtr *http.Transport, server string, headers map[string]string, namespace string, daemonSet string) (*DaemonSet, error) { | ||
client := &http.Client{Transport: transportPtr} | ||
url := server + "/apis/apps/v1beta2/namespaces/" + namespace + "/daemonsets/" + daemonSet | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for k, v := range headers { | ||
req.Header.Add(k, v) | ||
} | ||
|
||
resp, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
ds := &DaemonSet{} | ||
data, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = json.Unmarshal(data, &ds) | ||
|
||
if ds.Kind != "DaemonSet" { | ||
// Something went wrong! | ||
return nil, fmt.Errorf(fmt.Sprintf("Can not parse API response as DaemonSet: %s", string(data))) | ||
} | ||
|
||
return ds, err | ||
} | ||
|
||
func isImagesPresent(ds *DaemonSet) bool { | ||
desired := ds.Status.DesiredNumberScheduled | ||
ready := ds.Status.NumberReady | ||
|
||
log.Printf("%d of %d nodes currently has the required images.", desired, ready) | ||
|
||
return desired == ready | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# will delete itself unless the helm upgrade process is aborted | ||
{{ if .Values.imagePuller.hook.enabled }} | ||
{{ if .Values.prePuller.hook.enabled }} | ||
{{ template "jupyterhub.imagePuller.daemonset" (dict "hook" true "name" "hook-image-puller" "top" .) }} | ||
{{- end }} | ||
--- | ||
# will remain running and pull images on new nodes added to the cluster | ||
{{ if .Values.imagePuller.continuous.enabled }} | ||
{{ if .Values.prePuller.continuous.enabled }} | ||
{{ template "jupyterhub.imagePuller.daemonset" (dict "hook" false "name" "continuous-image-puller" "top" .) }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.