Skip to content

Commit

Permalink
reuse existing deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
eumel8 committed Jan 5, 2022
1 parent c2293a8 commit 5ca9069
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"
)

const appversion = "0.0.7"
const appversion = "0.0.8"

func main() {
// install namespace and app name
Expand All @@ -49,6 +49,7 @@ func main() {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
version := flag.Bool("version", false, "app version")
reuse := flag.Bool("reuse", false, "reuse existing deployment")

flag.Parse()

Expand Down Expand Up @@ -121,35 +122,37 @@ func main() {
},
}

// create DaemonSet, delete it if exists
fmt.Println("Creating daemonset...")
result, err := daemonsetsClient.Create(context.TODO(), daemonset, meta.CreateOptions{})
if errors.IsAlreadyExists(err) {
fmt.Println("daemonset already exists, deleting ... & exit")
deletePolicy := meta.DeletePropagationForeground
if err := daemonsetsClient.Delete(context.TODO(), app, meta.DeleteOptions{
PropagationPolicy: &deletePolicy,
}); err != nil {
if *reuse != true {
// create DaemonSet, delete it if exists
fmt.Println("Creating daemonset...")
result, err := daemonsetsClient.Create(context.TODO(), daemonset, meta.CreateOptions{})
if errors.IsAlreadyExists(err) {
fmt.Println("daemonset already exists, deleting ... & exit")
deletePolicy := meta.DeletePropagationForeground
if err := daemonsetsClient.Delete(context.TODO(), app, meta.DeleteOptions{
PropagationPolicy: &deletePolicy,
}); err != nil {
panic(err)
}
os.Exit(1)
} else if err != nil {
panic(err)
}
os.Exit(1)
} else if err != nil {
panic(err)
}
fmt.Printf("Created daemonset %q.\n", result.GetObjectMeta().GetName())

// wait here if all PODs are ready
for {
obj, err := clientset.AppsV1().DaemonSets(namespace).Get(context.TODO(), "overlaytest", meta.GetOptions{})
if err != nil {
fmt.Println("Error getting daemonset: %v", err)
panic(err.Error())
}
if obj.Status.NumberReady != 0 {
fmt.Println("all pods ready")
break
fmt.Printf("Created daemonset %q.\n", result.GetObjectMeta().GetName())

// wait here if all PODs are ready
for {
obj, err := clientset.AppsV1().DaemonSets(namespace).Get(context.TODO(), "overlaytest", meta.GetOptions{})
if err != nil {
fmt.Println("Error getting daemonset: %v", err)
panic(err.Error())
}
if obj.Status.NumberReady != 0 {
fmt.Println("all pods ready")
break
}
time.Sleep(2 * time.Second)
}
time.Sleep(2 * time.Second)
}

// load list of PODs
Expand Down

0 comments on commit 5ca9069

Please sign in to comment.