Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the secret for git-token #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.vscode/
501 changes: 0 additions & 501 deletions .idea/workspace.xml

This file was deleted.

78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# knap-cli

This is the repo for knap command line:

![knap_cli](doc/knap-cli.png)

## Command Overview
```$xslt
✔ $ ./knap-cli
knap-cli is used to create and manage knap application easily

Usage:
knap [command]

Available Commands:
bindService [Not implemented] Bind a service to one application
create Create a new knap appengine
delete Delete a knap appengine
edit Edit a knap appengine
get Get a knap appengine detail
help Help about any command
list List all knap appengines
logs Get a knap appengine logs
marketplace [Not implemented] Show service marketplace
services [Not implemented] Show all services
spaces [Not implemented] Show all spaces
templates List all knap templates
version Print the version number of knap cli

Flags:
--config string config file (default is $HOME/.knap.yaml)
-h, --help help for knap
-v, --verbose Print API request diagnostics to stdout

Use "knap [command] --help" for more information about a command.
```

## Create a new application
```$xslt
✘-1 $ ./knap-cli create helloworld -r https://github.com/bluebosh/knap-example -v master -s 2 -t build-and-deploy-pipeline
Application engine helloworld is created successfully
```

## List all applications
```$xslt
✔ $ ./knap-cli list
Application Name Version Ready Instance Domain
helloworld-appengine 1 Running 1/2 helloworld-default.knativepipeline.us-south.containers.appdomain.cloud
picalc-appengine 1 Running 1/1 picalc-default.knativepipeline.us-south.containers.appdomain.cloud

There are 2 application engine(s)
```

## Get an application
```$xslt
✔ $ ./knap-cli get helloworld-appengine
Application Name: helloworld-appengine
Application Version: 1
Application Git Repo: https://github.com/bluebosh/knap-example
Application Git Revision: master
Application Template: build-and-deploy-pipeline
Application Ready: Running
Application Status: Succeeded
Application Instance: 1
Application Size: 2
Application Domain: https://helloworld-default.knativepipeline.us-south.containers.appdomain.cloud
```

## Show all application templates
```$xslt
✔ $ ./knap-cli templates
Template Name Template Flow
build-and-deploy-pipeline source-to-image -> deploy-to-cluster
build-and-deploy-test-pipeline source-to-image -> deploy-to-cluster -> test-on-cluster
more-complex-pipeline source-to-image -> deploy-to-cluster -> blue-green-upgrade

There are 3 template(s)
```
132 changes: 129 additions & 3 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ import (
knapclientset "github.com/bluebosh/knap/pkg/client/clientset/versioned"
knapv1 "github.com/bluebosh/knap/pkg/apis/knap/v1alpha1"
"github.com/golang/glog"
"github.com/knative/eventing-contrib/contrib/github/pkg/apis/sources/v1alpha1"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/clientcmd"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc" // from https://github.com/kubernetes/client-go/issues/345
"github.com/fatih/color"
"strconv"
"k8s.io/client-go/kubernetes"
githubclientset "github.com/knative/eventing-contrib/contrib/github/pkg/client/clientset/versioned"
corev1 "k8s.io/api/core/v1"
servingclient "github.com/knative/serving/pkg/client/clientset/versioned"
knative_serving "github.com/knative/serving/pkg/apis/serving/v1beta1"
//channel "github.com/knative/eventing/pkg/apis/eventing/v1alpha1"
)

var foo string
Expand All @@ -42,11 +50,20 @@ var createCmd = &cobra.Command{
glog.Fatalf("Error building kubeconfig: %v", err)
}

knapClient, err := knapclientset.NewForConfig(cfg)
clientset, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building knap clientset: %v", err)
}

githubClient, err := githubclientset.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building knap clientset: %v", err)
}

knapClient, err := knapclientset.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building knap clientset: %v", err)
}

size, err:= strconv.ParseInt(cmd.Flag("size").Value.String(),10,32)
size32 := int32(size)
Expand All @@ -55,6 +72,113 @@ var createCmd = &cobra.Command{
fmt.Println("Error parsing size parameter", err)
}

gitAccessToken := cmd.Flag("git-access-token").Value.String()
gitRepo := cmd.Flag("gitrepo").Value.String()

if gitAccessToken != "" && gitRepo != "" {

s := v1.Secret{
TypeMeta: metav1.TypeMeta{
Kind: "Secret",
APIVersion: "apps/v1beta1",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "githubsecret",
},
StringData: map[string]string{
"accessToken": gitAccessToken,
"secretToken": "iTFLJhSMSk0=",
},
Type: "Opaque",
}

secret, err := clientset.CoreV1().Secrets("default").Create(&s)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf("Created Secret %q.\n", secret.GetObjectMeta().GetName())
}

servingClient, err := servingclient.NewForConfig(cfg)
if err != nil {
glog.Fatalf("Error building knap clientset: %v", err)
}
service := knative_serving.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "serving.knative.dev/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "github-event-receiver",
},
Spec: knative_serving.ServiceSpec {
ConfigurationSpec: knative_serving.ConfigurationSpec {
Template: knative_serving.RevisionTemplateSpec {
Spec: knative_serving.RevisionSpec {
PodSpec: corev1.PodSpec {
Containers: []v1.Container {
{
Image: "",
},
},
},

},

},
},

},
}
servingClient.ServingV1beta1().Services("default").Create(&service)

g := v1alpha1.GitHubSource{
TypeMeta: metav1.TypeMeta{
Kind: "GitHubSource",
APIVersion: "sources.eventing.knative.dev/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "githubsource",
},
Spec: v1alpha1.GitHubSourceSpec{
EventTypes: []string{"push"},
OwnerAndRepository: "mattcui/"+gitRepo,
AccessToken: v1alpha1.SecretValueFromSource {
SecretKeyRef: &corev1.SecretKeySelector {
LocalObjectReference: v1.LocalObjectReference {
Name: "githubsecret",
},
Key: "accessToken",

},
},
SecretToken: v1alpha1.SecretValueFromSource {
SecretKeyRef: &corev1.SecretKeySelector {
LocalObjectReference: v1.LocalObjectReference {
Name: "githubsecret",
},
Key: "secretToken",

},
},
Sink: &v1.ObjectReference{
Kind: "Service",
Name: "github-event-receiver",
},
},
}

_, err = githubClient.SourcesV1alpha1().GitHubSources("default").Create(&g)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Printf("Created Github resource %q.\n", secret.GetObjectMeta().GetName())
}
}

app := &knapv1.Appengine{
ObjectMeta: metav1.ObjectMeta{
Name: args[0] + "-appengine",
Expand All @@ -63,15 +187,16 @@ var createCmd = &cobra.Command{
Spec:
knapv1.AppengineSpec{
AppName: args[0],
GitRepo: cmd.Flag("gitrepo").Value.String(),
GitRepo: gitRepo,
GitAccessToken: gitAccessToken,
GitRevision: cmd.Flag("gitrevision").Value.String(),
// GitWatch: cmd.Flag("gitWatch").Value.String(),
Size: size32,
PipelineTemplate: cmd.Flag("template").Value.String(),
},
}
_, err = knapClient.KnapV1alpha1().Appengines("default").Create(app)

_, err = knapClient.KnapV1alpha1().Appengines("default").Create(app)
if err != nil {
//glog.Fatalf("Error creating application engine: %s", args[0])
fmt.Println("Error creating application engine", color.CyanString(args[0]), err)
Expand All @@ -94,6 +219,7 @@ func init() {
// is called directly, e.g.:
createCmd.Flags().StringP("resourcetype","e","", "The resource type the appengine [Not implemented]")
createCmd.Flags().StringP("gitrepo","r","", "The git repo of the appengine")
createCmd.Flags().StringP("git-access-token","r","", "The access token of the target application git repo")
createCmd.Flags().StringP("gitrevision","v","", "The git revision of the appengine")
createCmd.Flags().StringP("template","t","", "The template of the appengine")
createCmd.Flags().Int32P("size","s",1, "The size of the appengine")
Expand Down
2 changes: 1 addition & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var listCmd = &cobra.Command{
color.Cyan("%-30s%-20s%-20s%-20s%-20s\n", "Application Name", "Version", "Ready", "Instance", "Domain")
for i := 0; i < len(appLst.Items); i++ {
app := appLst.Items[i]
fmt.Printf("%-30s%-20s%-20s%-20s%-20s\n", app.Spec.AppName, app.Generation, app.Status.Ready, fmt.Sprint(app.Status.Instance) + "/" + fmt.Sprint(app.Spec.Size), app.Status.Domain)
fmt.Printf("%-30s%-20s%-20s%-20s%-20s\n", app.Name, fmt.Sprint(app.Generation), app.Status.Ready, fmt.Sprint(app.Status.Instance) + "/" + fmt.Sprint(app.Spec.Size), app.Status.Domain)
}
fmt.Println("\nThere are", color.CyanString("%v",len(appLst.Items)), "application engine(s)\n")
},
Expand Down
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func init() {
rootCmd.Flags().BoolP("verbose","v",false, "Print API request diagnostics to stdout")

//kubeconfig = "/Users/jordan/.bluemix/plugins/container-service/clusters/knative_pipeline/kube-config-dal10-knative_pipeline.yml"
kubeconfig = "/Users/jordanzt/.bluemix/plugins/container-service/clusters/knative_pipeline/kube-config-dal10-knative_pipeline.yml"
kubeconfig = os.Getenv("KUBECONFIG")
if kubeconfig == "" {
kubeconfig = "/Users/jordanzt/.bluemix/plugins/container-service/clusters/knative_pipeline/kube-config-dal10-knative_pipeline.yml"
}
}


Expand Down
Binary file added doc/knap-cli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/spf13/viper v1.4.0
github.com/tektoncd/pipeline v0.4.0
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
k8s.io/client-go v2.0.0-alpha.0.0.20181126152608-d082d5923d3c+incompatible
k8s.io/klog v0.3.3 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-containerregistry v0.0.0-20190611173133-6991786f9312 h1:rFgBtk8iSMgHOghDQTzp/2EsKmNo/hfgBoxQ+TZdNgM=
github.com/google/go-containerregistry v0.0.0-20190611173133-6991786f9312/go.mod h1:yZAFP63pRshzrEYLXLGPmUt0Ay+2zdjmMN1loCnRLUk=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
Expand Down Expand Up @@ -139,9 +140,12 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/knative/build v0.6.0 h1:tAhqGbRL3/wFOfEc4srO8XDNV8DxUE+z6TzKW0JPWsE=
github.com/knative/build v0.6.0/go.mod h1:/sU74ZQkwlYA5FwYDJhYTy61i/Kn+5eWfln2jDbw3Qo=
github.com/knative/eventing-contrib v0.6.0 h1:ScjLMLfJ3ANsWSRIAGV1hRejbEbCPEoJkiwADKPKTug=
github.com/knative/pkg v0.0.0-20190610153941-28f181241cdb h1:X/FTe0HyoDh1Vn285dR2s5WpQ309RA6Rxe/YluyDN2s=
github.com/knative/pkg v0.0.0-20190610153941-28f181241cdb/go.mod h1:7Ijfhw7rfB+H9VtosIsDYvZQ+qYTz7auK3fHW/5z4ww=
github.com/knative/serving v0.6.1 h1:Q9MYY1nebuoykvYIqIR5faOOPpdomURC0p1RJQPZfbk=
github.com/knative/serving v0.6.1/go.mod h1:ljvMfwQy2qanaM/8xnBSK4Mz3Vv2NawC2fo5kFRJS1A=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
Expand Down
Binary file modified knap-cli
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions vendor/github.com/ghodss/yaml/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading