Skip to content

Commit

Permalink
feedback changes
Browse files Browse the repository at this point in the history
Signed-off-by: Nitishkumar Singh <[email protected]>
  • Loading branch information
nitishkumar71 authored and alexellis committed Feb 28, 2024
1 parent 0846af8 commit 6e40ab0
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 47 deletions.
10 changes: 6 additions & 4 deletions example/create-namespace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -37,22 +36,25 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Create Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Create Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
fmt.Println("Get Namespace")
time.Sleep(15 * time.Second)
ns, err := client.GetNamespace(context.Background(), "test-namespace")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Namespace: %v \n", ns)

// delete namespace
err = client.DeleteNamespace(context.Background(), "test-namespace")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
10 changes: 6 additions & 4 deletions example/create-secret/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -34,14 +33,16 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Create Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Create Failed: %s", status, err)
os.Exit(1)
}

// Get Secrets
secrets, err := client.GetSecrets(context.Background(), "openfaas-fn")
// non 200 status value will have some error
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}

for _, s := range secrets {
Expand All @@ -51,7 +52,8 @@ func main() {
err = client.DeleteSecret(context.Background(), "env-store-test", "openfaas-fn")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}

}
10 changes: 6 additions & 4 deletions example/deploy-function/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -37,22 +36,25 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Deploy Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Deploy Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
fmt.Println("Get Function")
time.Sleep(15 * time.Second)
fn, err := client.GetFunction(context.Background(), "env-store-test", "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Function: %v \n", fn)

// delete function
err = client.DeleteFunction(context.Background(), "env-store-test", "openfaas-fn")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
13 changes: 8 additions & 5 deletions example/get-functions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand All @@ -27,7 +26,8 @@ func main() {

fns, err := client.GetFunctions(context.Background(), "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("No Of Functions: %d\n", len(fns))

Expand All @@ -42,18 +42,21 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Deploy Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Deploy Failed: %s", status, err)
os.Exit(1)
}

fns, err = client.GetFunctions(context.Background(), "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("No Of Functions: %d\n", len(fns))

err = client.DeleteFunction(context.Background(), "env-store-test", "openfaas-fn")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
13 changes: 8 additions & 5 deletions example/get-namepsaces/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand All @@ -27,7 +26,8 @@ func main() {

ns, err := client.GetNamespaces(context.Background())
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("No Of Namespaces: %d\n", len(ns))

Expand All @@ -36,19 +36,22 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Create Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Create Failed: %s", status, err)
os.Exit(1)
}

ns, err = client.GetNamespaces(context.Background())
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("No Of Namespaces: %d\n", len(ns))

// delete namespace
err = client.DeleteNamespace(context.Background(), "test-namespace")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
7 changes: 4 additions & 3 deletions example/logs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -35,7 +34,8 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Deploy Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Deploy Failed: %s", status, err)
os.Exit(1)
}

// Follow is allows the user to request a stream of logs until the timeout
Expand All @@ -47,7 +47,8 @@ func main() {

logsChan, err := client.GetLogs(context.Background(), "env-store-test", "openfaas-fn", follow, tail, &since)
if err != nil {
log.Printf("Get Logs Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Logs Failed: %s", err)
os.Exit(1)
}

fmt.Println("Logs Received....")
Expand Down
16 changes: 10 additions & 6 deletions example/scale-function/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -38,36 +37,41 @@ func main() {

// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Deploy Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Deploy Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
time.Sleep(15 * time.Second)
fn, err := client.GetFunction(context.Background(), "env-store-test", "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Function Replica: %d \n", fn.Replicas)

// scale functions
err = client.ScaleFunction(context.Background(), "env-store-test", "openfaas-fn", uint64(2))
// non 200 status value will have some error
if err != nil {
log.Printf("Scale Failed: %s", err)
fmt.Fprintf(os.Stderr, "Scale Failed: %s", err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
time.Sleep(15 * time.Second)
fn, err = client.GetFunction(context.Background(), "env-store-test", "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Function Replica: %d \n", fn.Replicas)

// delete function
err = client.DeleteFunction(context.Background(), "env-store-test", "openfaas-fn")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
16 changes: 10 additions & 6 deletions example/update-function/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -38,15 +37,17 @@ func main() {

// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Deploy Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Deploy Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
fmt.Println("Get Function")
time.Sleep(15 * time.Second)
fn, err := client.GetFunction(context.Background(), "env-store-test", "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Function: %v \n", fn)

Expand All @@ -62,22 +63,25 @@ func main() {

// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Update Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Update Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
fmt.Println("Get Function")
time.Sleep(15 * time.Second)
fn, err = client.GetFunction(context.Background(), "env-store-test", "openfaas-fn")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Function: %v \n", fn)

// delete function
err = client.DeleteFunction(context.Background(), "env-store-test", "openfaas-fn")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
16 changes: 10 additions & 6 deletions example/update-namespace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -37,15 +36,17 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Create Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Create Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
fmt.Println("Get Namespace Before Update")
time.Sleep(15 * time.Second)
ns, err := client.GetNamespace(context.Background(), "test-namespace")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Namespace: %v \n", ns)

Expand All @@ -60,22 +61,25 @@ func main() {
})
// non 200 status value will have some error
if err != nil {
log.Printf("Status: %d Update Failed: %s", status, err)
fmt.Fprintf(os.Stderr, "Status: %d Update Failed: %s", status, err)
os.Exit(1)
}

fmt.Println("Wait for 15 seconds....")
fmt.Println("Get Namespace After Update")
time.Sleep(15 * time.Second)
ns, err = client.GetNamespace(context.Background(), "test-namespace")
if err != nil {
log.Printf("Get Failed: %s", err)
fmt.Fprintf(os.Stderr, "Get Failed: %s", err)
os.Exit(1)
}
fmt.Printf("Namespace: %v \n", ns)

// delete namespace
err = client.DeleteNamespace(context.Background(), "test-namespace")
// non 200 status value will have some error
if err != nil {
log.Printf("Delete Failed: %s", err)
fmt.Fprintf(os.Stderr, "Delete Failed: %s", err)
os.Exit(1)
}
}
Loading

0 comments on commit 6e40ab0

Please sign in to comment.