Skip to content

Commit

Permalink
refactor: implement new way of installing kwok
Browse files Browse the repository at this point in the history
- for >= v0.4.0 versions of kwok
  • Loading branch information
vadasambar committed Sep 6, 2023
1 parent 27d1913 commit e584233
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,37 @@ $ go run main.go
```

### Misc
`main.go` is basically a go implementation of `alternative-install.sh`
`main.go` is basically a go implementation of `alternative-install.sh`

### Output
```
$ go run main.go
deploymentAndCRDs URL https://github.com/kubernetes-sigs/kwok/releases/download/v0.4.0/kwok.yaml
INFO[0000] kubectl apply -f https://github.com/kubernetes-sigs/kwok/releases/download/v0.4.0/kwok.yaml
INFO[0004] kubectl output:
customresourcedefinition.apiextensions.k8s.io/attaches.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/clusterattaches.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/clusterexecs.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/clusterlogs.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/clusterportforwards.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/execs.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/logs.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/metrics.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/portforwards.kwok.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/stages.kwok.x-k8s.io created
serviceaccount/kwok-controller created
clusterrole.rbac.authorization.k8s.io/kwok-controller created
clusterrolebinding.rbac.authorization.k8s.io/kwok-controller created
service/kwok-controller created
deployment.apps/kwok-controller created
stagesCRs URL https://github.com/kubernetes-sigs/kwok/releases/download/v0.4.0/stage-fast.yaml
INFO[0004] kubectl apply -f https://github.com/kubernetes-sigs/kwok/releases/download/v0.4.0/stage-fast.yaml
INFO[0006] kubectl output:
stage.kwok.x-k8s.io/node-heartbeat-with-lease created
stage.kwok.x-k8s.io/node-initialize created
stage.kwok.x-k8s.io/pod-complete created
stage.kwok.x-k8s.io/pod-delete created
stage.kwok.x-k8s.io/pod-ready created
```

![](./images/2023-09-06-11-28-54.png)
Binary file added images/2023-09-06-11-28-54.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
65 changes: 64 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ const (
apply action = "apply"
delete action = "delete"
minVersion = "v0.4.0"
kwokRepo = "kubernetes-sigs/kwok"
)

var installRelease string

func main() {
rel, err := GetLatestKwokRelease()
if err != nil {
Expand All @@ -41,8 +44,68 @@ func main() {
log.Fatalf("latest release %s is a lower version than min required version %s\n", rel, minVersion)
}

LegacyInstallAndUninstall(rel)
installRelease = rel

// clean existing release if any
if err := UninstallKwok(); err != nil {
panic(err)
}

if err := InstallKwok(); err != nil {
panic(err)
}

time.Sleep(time.Second * 20)
if err := UninstallKwok(); err != nil {
panic(err)
}

}

// InstallKwok installs kwok >= v0.4.0
// Based on https://kwok.sigs.k8s.io/docs/user/kwok-in-cluster/#deploy-kwok-in-a-cluster
func InstallKwok() error {
return kwokKubectl(apply, nil)
}

// UninstallKwok uninstalls kwok >= v0.4.0
// Based on https://kwok.sigs.k8s.io/docs/user/kwok-in-cluster/#deploy-kwok-in-a-cluster
func UninstallKwok() error {
return kwokKubectl(delete, []string{"--ignore-not-found=true"})
}

func kwokKubectl(action action, extraArgs []string) error {
deploymentAndCRDs := fmt.Sprintf("https://github.com/%s/releases/download/%s/kwok.yaml", kwokRepo, installRelease)
// fmt.Println("deploymentAndCRDs URL", deploymentAndCRDs) // for debugging
// `kubectl apply` deployment and CRDs
cmd := []string{
"kubectl", string(action), "-f", deploymentAndCRDs,
}
if len(extraArgs) > 0 {
cmd = append(cmd, extraArgs...)
}
o, err := runKubectl(cmd...)
if err != nil {
return err
}
log.Infof("kubectl output: \n%s", string(o))

stagesCRs := fmt.Sprintf("https://github.com/%s/releases/download/%s/stage-fast.yaml", kwokRepo, installRelease)
// fmt.Println("stagesCRs URL", stagesCRs) // for debugging
// `kubectl apply` stages
cmd = []string{
"kubectl", string(action), "-f", stagesCRs,
}
if len(extraArgs) > 0 {
cmd = append(cmd, extraArgs...)
}
o, err = runKubectl(cmd...)
if err != nil {
return err
}
log.Infof("kubectl output: \n%s", string(o))

return nil
}

// LegacyInstallAndUninstall installs and uninstalls kwok the legacy way
Expand Down

0 comments on commit e584233

Please sign in to comment.