Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #70 from remyLemeunier/add_k8s_vcsversion
Browse files Browse the repository at this point in the history
Add list VCS version for k8s
  • Loading branch information
remyLemeunier authored Oct 19, 2017
2 parents b5de443 + e0d55ae commit 0fe9f69
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
30 changes: 28 additions & 2 deletions deployers/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"path"
"regexp"

"github.com/remyLemeunier/contactkey/utils"
"github.com/remyLemeunier/k8s-deploy/releases"
Expand All @@ -20,6 +21,7 @@ type DeployerK8s struct {
values []string
Environments map[string]utils.K8sEnvironment
workPath string
vcsRegexp string
}

func NewDeployerK8s(cfg utils.DeployerK8sConfig, manifest utils.DeployerK8sManifest) (*DeployerK8s, error) {
Expand All @@ -33,6 +35,7 @@ func NewDeployerK8s(cfg utils.DeployerK8sConfig, manifest utils.DeployerK8sManif
deployer.Namespace = manifest.Namespace
deployer.Environments = cfg.Environments
deployer.workPath = cfg.WorkPath
deployer.vcsRegexp = cfg.VcsRegexp
return &deployer, nil
}

Expand Down Expand Up @@ -71,9 +74,32 @@ func (d *DeployerK8s) ListInstances(env string) ([]Instance, error) {
}

func (d *DeployerK8s) ListVcsVersions(env string) ([]string, error) {
//TODO: implement this
context, err := d.getK8sContext(env)
if err != nil {
return nil, err
}

log.Debug("ListVcsVersions")
return []string{"0"}, nil
log.Debugf("Environment %s matched to : cluster=%s", env, context.Cluster)

if d.Release == nil {
d.Release, err = d.getRelease(context.Cluster, d.Namespace)
if err != nil {
return nil, err
}
}

content, err := d.Release.Content()
if err != nil {
return nil, err
}

vcsVersion := regexp.MustCompile(d.vcsRegexp).FindStringSubmatch(content.String())
if len(vcsVersion) != 2 {
return nil, fmt.Errorf("Could not find vcsVersion")
}

return []string{vcsVersion[1]}, nil
}

func (d *DeployerK8s) getK8sContext(env string) (utils.K8sEnvironment, error) {
Expand Down
2 changes: 2 additions & 0 deletions examples/config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ deployers:
workPath: /tmp
environments:
preprod: pp

k8s:
vcsRegexp: -v(.+)
workPath: /tmp
environments:
local:
Expand Down
1 change: 1 addition & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type K8sEnvironment struct {
type DeployerK8sConfig struct {
WorkPath string `mapstructure:"workPath"`
Environments map[string]K8sEnvironment `mapstructure:"environments"`
VcsRegexp string `mapstructure:"vcsRegexp"`
}

type DeployerGgnConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions utils/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ deployers:
preprod: pp
prod: da-prod

k8s:
vcsRegexp: tag:\s?v(.+)
workPath: /tmp
environments:
local:
cluster: ops

sources:
stash:
user: user
Expand Down

0 comments on commit 0fe9f69

Please sign in to comment.