Skip to content

Commit

Permalink
Update current feature
Browse files Browse the repository at this point in the history
  • Loading branch information
fjammes committed Jan 5, 2024
1 parent e94695f commit c6088d7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
96 changes: 96 additions & 0 deletions cmd/exist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright © 2023 Fabrice Jammmes [email protected]
*/
package cmd

import (
"github.com/spf13/cobra"
)

// deskCmd represents the desk command
var existCmd = &cobra.Command{
Use: "exist",
Aliases: []string{"e"},
Short: "Wait for a kubernetes resource to exist",
Long: `Lauch a interactive shell with k8s client tools installed, inside a docker container, it mounts host directories $HOME/.kube in $HOME/.kube and homefs/ in $HOME`,
Run: func(cmd *cobra.Command, args []string) {

// TODO

},
}

func init() {
rootCmd.AddCommand(existCmd)

}

// package main

// import (
// "context"
// "flag"
// "fmt"
// "os"
// "time"

// corev1 "k8s.io/api/core/v1"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/client-go/kubernetes"
// "k8s.io/client-go/tools/clientcmd"
// )

// func waitForExist(clientset *kubernetes.Clientset, ns string, resourceType string, maxWaitSecs int, resource string) error {
// intervalSecs := 2 * time.Second
// startTime := time.Now()

// for {
// fmt.Printf("Waiting for %s %s\n", resourceType, resource)

// if time.Since(startTime).Seconds() > float64(maxWaitSecs) {
// return fmt.Errorf("waited for %s in namespace \"%s\" to exist for %d seconds without luck", resourceType, ns, maxWaitSecs)
// }

// _, err := clientset.CoreV1().Namespaces().Get(context.Background(), resource, metav1.GetOptions{})

// if err == nil {
// break
// } else {
// time.Sleep(intervalSecs)
// }
// }

// return nil
// }

// func main() {
// kubeconfig := flag.String("kubeconfig", "~/.kube/config", "path to the kubeconfig file")
// ns := flag.String("namespace", "", "the namespace")
// resourceType := flag.String("type", "", "the resource type")
// maxWaitSecs := flag.Int("timeout", 120, "the maximum wait time in seconds")
// flag.Parse()
// args := flag.Args()

// if len(args) < 1 {
// fmt.Println("Please provide a resource to check")
// os.Exit(1)
// }

// resource := args[0]

// config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
// if err != nil {
// panic(err)
// }

// clientset, err := kubernetes.NewForConfig(config)
// if err != nil {
// panic(err)
// }

// err = waitForExist(clientset, *ns, *resourceType, *maxWaitSecs, resource)
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
// }
2 changes: 1 addition & 1 deletion resources/install-argocd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ curl -sSL -o /tmp/argocd-linux-amd64 https://github.com/argoproj/argo-cd/release
sudo install -m 555 /tmp/argocd-linux-amd64 /usr/local/bin/argocd
rm /tmp/argocd-linux-amd64

wait_for_exist argocd statefulset.apps 120
wait_for_exist argocd statefulset.apps 120
for obj in statefulset.apps/argocd-application-controller deployment.apps/argocd-redis deployment.apps/argocd-repo-server deployment.apps/argocd-server; do
echo "Wait for $obj to be ready"
kubectl rollout status $obj --timeout="${WAIT_TIMEOUT}s" -n argocd
Expand Down

0 comments on commit c6088d7

Please sign in to comment.