Skip to content

Commit

Permalink
add namespace to cluster resource.
Browse files Browse the repository at this point in the history
I expect this to reduce args passed to `kubectl apply`.

Signed-off-by: cappyzawa <cappyzawa@yahoo.ne.jp>
  • Loading branch information
cappyzawa committed Sep 1, 2019
1 parent 3950521 commit a10b3c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
5 changes: 3 additions & 2 deletions cmd/kubeconfigwriter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func createKubeconfigFile(resource *v1alpha1.ClusterResource, logger *zap.Sugare
Password: pass,
}
context := &clientcmdapi.Context{
Cluster: resource.Name,
AuthInfo: resource.Username,
Cluster: resource.Name,
AuthInfo: resource.Username,
Namespace: resource.Namespace,
}
c := clientcmdapi.NewConfig()
c.Clusters[resource.Name] = cluster
Expand Down
1 change: 1 addition & 0 deletions docs/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ The Cluster resource has the following parameters:
- `url` (required): Host url of the master node
- `username` (required): the user with access to the cluster
- `password`: to be used for clusters with basic auth
- `namespace`: The namespace to be given to the target namespace
- `token`: to be used for authentication, if present will be used ahead of the
password
- `insecure`: to indicate server should be accessed without verifying the TLS
Expand Down
26 changes: 15 additions & 11 deletions pkg/apis/pipeline/v1alpha1/cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ type ClusterResource struct {
URL string `json:"url"`
Revision string `json:"revision"`
// Server requires Basic authentication
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username"`
Password string `json:"password"`
Namespace string `json:"namespace"`
// Server requires Bearer authentication. This client will not attempt to use
// refresh tokens for an OAuth2 flow.
// Token overrides userame and password
Expand Down Expand Up @@ -74,6 +75,8 @@ func NewClusterResource(r *PipelineResource) (*ClusterResource, error) {
clusterResource.Revision = param.Value
case strings.EqualFold(param.Name, "Username"):
clusterResource.Username = param.Value
case strings.EqualFold(param.Name, "Namespace"):
clusterResource.Namespace = param.Value
case strings.EqualFold(param.Name, "Password"):
clusterResource.Password = param.Value
case strings.EqualFold(param.Name, "Token"):
Expand Down Expand Up @@ -121,15 +124,16 @@ func (s *ClusterResource) GetURL() string {
// Replacements is used for template replacement on a ClusterResource inside of a Taskrun.
func (s *ClusterResource) Replacements() map[string]string {
return map[string]string{
"name": s.Name,
"type": string(s.Type),
"url": s.URL,
"revision": s.Revision,
"username": s.Username,
"password": s.Password,
"token": s.Token,
"insecure": strconv.FormatBool(s.Insecure),
"cadata": string(s.CAData),
"name": s.Name,
"type": string(s.Type),
"url": s.URL,
"revision": s.Revision,
"username": s.Username,
"password": s.Password,
"namespace": s.Namespace,
"token": s.Token,
"insecure": strconv.FormatBool(s.Insecure),
"cadata": string(s.CAData),
}
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/pipeline/v1alpha1/cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ func TestNewClusterResource(t *testing.T) {
Token: "my-token",
Insecure: true,
},
}, {
desc: "basic cluster resource with namespace",
resource: tb.PipelineResource("test-cluster-resource", "default", tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeCluster,
tb.PipelineResourceSpecParam("name", "test_cluster_resource"),
tb.PipelineResourceSpecParam("url", "http://10.10.10.10"),
tb.PipelineResourceSpecParam("cadata", "bXktY2x1c3Rlci1jZXJ0Cg"),
tb.PipelineResourceSpecParam("token", "my-token"),
tb.PipelineResourceSpecParam("namespace", "my-namespace"),
)),
want: &v1alpha1.ClusterResource{
Name: "test_cluster_resource",
Type: v1alpha1.PipelineResourceTypeCluster,
URL: "http://10.10.10.10",
CAData: []byte("my-cluster-cert"),
Token: "my-token",
Namespace: "my-namespace",
},
}, {
desc: "basic resource with secrets",
resource: tb.PipelineResource("test-cluster-resource", "default", tb.PipelineResourceSpec(
Expand Down

0 comments on commit a10b3c4

Please sign in to comment.