Skip to content

Instantly share code, notes, and snippets.

@ahmetb
Last active August 19, 2020 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmetb/11215f88e70853eca52157765af5896b to your computer and use it in GitHub Desktop.
Save ahmetb/11215f88e70853eca52157765af5896b to your computer and use it in GitHub Desktop.
using Knative API with Cloud Run client library
package main
import (
"context"
"log"
"net/http"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
"google.golang.org/api/run/v1"
)
func main() {
ctx := context.Background()
tr := http.DefaultTransport.(*http.Transport).Clone()
// TODO set up a cert pool with Kubernetes master CA cert
tr. TLSClientConfig.InsecureSkipVerify = true
ts, err := google.DefaultTokenSource(ctx, "cloud-platform")
if err != nil {
panic(err)
}
atr := &oauth2.Transport{
Base: tr,
Source: ts}
hc := &http.Client{Transport: atr}
runService, err := run.NewService(ctx,
option.WithHTTPClient(hc),
option.WithEndpoint("https://146.148.59.112/"))
if err != nil {
panic(err)
}
resp, err := runService.Namespaces.Services.Delete("namespaces/default/services/hello").Do()
if err != nil {
panic(err)
}
log.Println(resp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment