Skip to content

Commit

Permalink
Merge pull request #101 from ashanaakh/kube-token
Browse files Browse the repository at this point in the history
Added kubernetes token support
  • Loading branch information
calj authored Dec 14, 2017
2 parents 75ef947 + 82d5cb1 commit 48517e4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
35 changes: 15 additions & 20 deletions bin/concourse/out
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,28 @@ params = Kite::Helpers::Concourse.params(STDIN.read)

Kite::Helpers::Concourse.fatal '`source` missing' unless params['source']

key = params['source']['json_key']
kubeconfig = params['source']['kubeconfig']
token = params['source']['token'] # kubectl service account token
endpoint = params['source']['endpoint']
cert = params['source']['certificate-authority']
command = params['params']['command']

Kite::Helpers::Concourse.fatal '`kubeconfig` missing' if kubeconfig.to_s.empty?
Kite::Helpers::Concourse.fatal '`command` missing' if command.to_s.empty?

path_certificate = '/tmp/ca.crt'
path_key = '/tmp/key.json'
path_kubeconfig = '/tmp/kubeconfig'

File.write(path_key, key) if key
File.write(path_kubeconfig, kubeconfig)

env = {
'KUBECONFIG' => path_kubeconfig,
}

if key
env['GOOGLE_CREDENTIALS'] = path_key
unless Kite::Helpers::Concourse.execute("gcloud auth activate-service-account --key-file=#{ path_key }", env)
::Kite::Helpers::Concourse.respond(
version: { status: 'error' },
metadata: ["Failed to execute command #{ command }"]
)
exit 1
end
end
env = {}

File.write(path_certificate, cert)
env['KUBECONFIG'] = path_kubeconfig

Kite::Helpers::Concourse.execute("kubectl config set-cluster concourse " \
"--embed-certs=true --server=#{ endpoint } " \
"--certificate-authority=#{ path_certificate }", env)
Kite::Helpers::Concourse.execute("kubectl config set-credentials concourse --token='#{ token }'", env)
Kite::Helpers::Concourse.execute("kubectl config set-context concourse --cluster=concourse --user=concourse", env)
Kite::Helpers::Concourse.execute("kubectl config use-context concourse", env)

if Kite::Helpers::Concourse.execute(command, env)
::Kite::Helpers::Concourse.respond(version: { status: 'ok' })
Expand Down
45 changes: 45 additions & 0 deletions docs/kite-concourse-resource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Kite concourse resource

When you define kite resource you should defind `kubeconfig` or kite can generate it from defined `token`, `endpoint`, `user`, `cluster`, `certificate-authority` parameters.

Here is description of parameters:
- __token__ - service account token for your cluster
- __endpoint__ - cluster server adress
- __certificate-autority__ - service account certificate for cluster

### Where to get this parameters ?

Get secret's name
```shell
kubectl get serviceAccount <service_account_name> -oyaml
echo -n SECRET | base64 -d
```

Then look on secret's yaml. Here you can find certificate-authority and token values:
```shell
kubectl get secrets <secrets_name> -oyaml
echo -n SECRET | base64 -d
```

Find server address:
```shell
kubectl config view
```

*Example*

```yaml
resource_types:
- name: kite
type: docker-image
source:
repository: heliostech/kite

resources:
- name: kite-test
type: kite
source:
token: {{sa_token}}
endpoint: {{server_ip}}
certificate-autority: {{certificate-autority}}
```

0 comments on commit 48517e4

Please sign in to comment.