Skip to content

Commit 9f0c46f

Browse files
Support new kubernetes-runner-type option (#35)
1 parent 8267572 commit 9f0c46f

File tree

14 files changed

+224
-8
lines changed

14 files changed

+224
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "venona",
3-
"version": "0.21.0",
3+
"version": "0.22.0",
44
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
55
"main": "index.js",
66
"scripts": {

venonactl/cmd/install.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var installCmdOptions struct {
4444
installOnlyRuntimeEnvironment bool
4545
skipRuntimeInstallation bool
4646
runtimeEnvironmentName string
47+
kubernetesRunnerType bool
4748
}
4849

4950
// installCmd represents the install command
@@ -67,7 +68,13 @@ var installCmd = &cobra.Command{
6768
StorageClass: installCmdOptions.storageClass,
6869
IsDefaultStorageClass: isDefault,
6970
DryRun: installCmdOptions.dryRun,
71+
KubernetesRunnerType: installCmdOptions.kubernetesRunnerType,
7072
}
73+
74+
if installCmdOptions.kubernetesRunnerType {
75+
builder.Add(plugins.EnginePluginType)
76+
}
77+
7178
if isDefault {
7279
builderInstallOpt.StorageClass = plugins.DefaultStorageClassNamePrefix
7380
}
@@ -159,4 +166,5 @@ func init() {
159166
installCmd.Flags().BoolVar(&installCmdOptions.installOnlyRuntimeEnvironment, "only-runtime-environment", false, "Set to true to onlky configure namespace as runtime-environment for Codefresh")
160167
installCmd.Flags().BoolVar(&installCmdOptions.dryRun, "dry-run", false, "Set to true to simulate installation")
161168
installCmd.Flags().BoolVar(&installCmdOptions.setDefaultRuntime, "set-default", false, "Mark the install runtime-environment as default one after installation")
169+
installCmd.Flags().BoolVar(&installCmdOptions.kubernetesRunnerType, "kubernetes-runner-type", false, "Set the runner type to kubernetes (alpha feature)")
162170
}

venonactl/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/codefresh-io/venona/venonactl
33
require (
44
contrib.go.opencensus.io/exporter/ocagent v0.4.3 // indirect
55
github.com/Azure/go-autorest v11.4.0+incompatible // indirect
6-
github.com/codefresh-io/go-sdk v0.10.0
6+
github.com/codefresh-io/go-sdk v0.13.0
77
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
88
github.com/dustin/go-humanize v1.0.0
99
github.com/go-stack/stack v1.8.0 // indirect

venonactl/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
1414
github.com/census-instrumentation/opencensus-proto v0.1.0-0.20181214143942-ba49f56771b8 h1:gUqsFVdUKoRHNg8fkFd8gB5OOEa/g5EwlAHznb4zjbI=
1515
github.com/census-instrumentation/opencensus-proto v0.1.0-0.20181214143942-ba49f56771b8/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
1616
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
17-
github.com/codefresh-io/go-sdk v0.10.0 h1:xgfkapCLrx2FHofWq9LRsH0bLcNgwPZWQZTttCvMUng=
18-
github.com/codefresh-io/go-sdk v0.10.0/go.mod h1:U8c2f9/Vb2SXFbeKHSzofUOp3N78pDC3YdshFsUfdgc=
17+
github.com/codefresh-io/go-sdk v0.13.0 h1:puGXvsMISaA3yoFsnf5YSziR8IEHBlATG+KQPvCflrY=
18+
github.com/codefresh-io/go-sdk v0.13.0/go.mod h1:U8c2f9/Vb2SXFbeKHSzofUOp3N78pDC3YdshFsUfdgc=
1919
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
2020
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
2121
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=

venonactl/pkg/codefresh/cfapi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type (
4141
MarkAsDefault bool
4242
StorageClass string
4343
IsDefaultStorageClass bool
44+
KubernetesRunnerType bool
4445
}
4546

4647
RuntimeEnvironmentRegistrator interface {
@@ -58,6 +59,7 @@ type (
5859
markAsDefault bool
5960
storageClass string
6061
isDefaultStorageClass bool
62+
kubernetesRunnerType bool
6163
}
6264

6365
logger interface {
@@ -80,6 +82,7 @@ func NewCodefreshAPI(opt *APIOptions) API {
8082
registerWithAgent: opt.RegisterWithAgent,
8183
storageClass: opt.StorageClass,
8284
isDefaultStorageClass: opt.IsDefaultStorageClass,
85+
kubernetesRunnerType: opt.KubernetesRunnerType,
8386
}
8487
}
8588

@@ -162,6 +165,9 @@ func (a *api) Register() (*codefresh.RuntimeEnvironment, error) {
162165
HasAgent: a.registerWithAgent,
163166
Cluster: a.clustername,
164167
}
168+
if a.kubernetesRunnerType {
169+
options.RunnerType = codefresh.KubernetesRunnerType
170+
}
165171

166172
options.StorageClass = fmt.Sprintf("%s-%s", a.storageClass, a.clusternamespace)
167173
if !a.isDefaultStorageClass {

venonactl/pkg/logger/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func New(o *Options) Logger {
2121
"Command": o.Command,
2222
})
2323
handlers := []log.Handler{}
24-
lvl := log.LvlError
24+
lvl := log.LvlInfo
2525
if o.Verbose {
2626
lvl = log.LvlDebug
2727
}

venonactl/pkg/plugins/engine.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
Copyright 2019 The Codefresh Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package plugins
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/codefresh-io/venona/venonactl/pkg/logger"
23+
"github.com/codefresh-io/venona/venonactl/pkg/obj/kubeobj"
24+
templates "github.com/codefresh-io/venona/venonactl/pkg/templates/kubernetes"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
)
27+
28+
// enginePlugin installs assets on Kubernetes Dind runtimectl Env
29+
type enginePlugin struct {
30+
logger logger.Logger
31+
}
32+
33+
const (
34+
engineFilesPattern = ".*.engine.yaml"
35+
)
36+
37+
// Install venona agent
38+
func (u *enginePlugin) Install(opt *InstallOptions, v Values) (Values, error) {
39+
cs, err := opt.KubeBuilder.BuildClient()
40+
if err != nil {
41+
u.logger.Error(fmt.Sprintf("Cannot create kubernetes clientset: %v ", err))
42+
return nil, err
43+
}
44+
return v, install(&installOptions{
45+
logger: u.logger,
46+
templates: templates.TemplatesMap(),
47+
templateValues: v,
48+
kubeClientSet: cs,
49+
namespace: opt.ClusterNamespace,
50+
matchPattern: engineFilesPattern,
51+
dryRun: opt.DryRun,
52+
operatorType: EnginePluginType,
53+
})
54+
}
55+
56+
// Status of runtimectl environment
57+
func (u *enginePlugin) Status(statusOpt *StatusOptions, v Values) ([][]string, error) {
58+
cs, err := statusOpt.KubeBuilder.BuildClient()
59+
if err != nil {
60+
u.logger.Error(fmt.Sprintf("Cannot create kubernetes clientset: %v ", err))
61+
return nil, err
62+
}
63+
opt := &statusOptions{
64+
logger: u.logger,
65+
templates: templates.TemplatesMap(),
66+
templateValues: v,
67+
kubeClientSet: cs,
68+
namespace: statusOpt.ClusterNamespace,
69+
matchPattern: engineFilesPattern,
70+
operatorType: EnginePluginType,
71+
}
72+
return status(opt)
73+
}
74+
75+
func (u *enginePlugin) Delete(deleteOpt *DeleteOptions, v Values) error {
76+
cs, err := deleteOpt.KubeBuilder.BuildClient()
77+
if err != nil {
78+
u.logger.Error(fmt.Sprintf("Cannot create kubernetes clientset: %v ", err))
79+
return nil
80+
}
81+
opt := &deleteOptions{
82+
logger: u.logger,
83+
templates: templates.TemplatesMap(),
84+
templateValues: v,
85+
kubeClientSet: cs,
86+
namespace: deleteOpt.ClusterNamespace,
87+
matchPattern: engineFilesPattern,
88+
operatorType: EnginePluginType,
89+
}
90+
return delete(opt)
91+
}
92+
93+
func (u *enginePlugin) Upgrade(opt *UpgradeOptions, v Values) (Values, error) {
94+
95+
// replace of sa creates new secert with sa creds
96+
// avoid it till patch fully implemented
97+
var skipUpgradeFor = map[string]interface{}{
98+
"service-account.venona.yaml": nil,
99+
}
100+
101+
var err error
102+
103+
kubeClientset, err := opt.KubeBuilder.BuildClient()
104+
if err != nil {
105+
u.logger.Error(fmt.Sprintf("Cannot create kubernetes clientset: %v ", err))
106+
return nil, err
107+
}
108+
109+
// special case when we need to get the token from the remote to no regenrate it
110+
// whole flow should be more like kubectl apply that build a patch
111+
// based on remote object and candidate object
112+
113+
secret, err := kubeClientset.CoreV1().Secrets(opt.ClusterNamespace).Get(opt.Name, metav1.GetOptions{})
114+
if err != nil {
115+
return nil, err
116+
}
117+
token := secret.Data["codefresh.token"]
118+
v["AgentToken"] = string(token)
119+
120+
kubeObjects, err := getKubeObjectsFromTempalte(v, engineFilesPattern, u.logger)
121+
if err != nil {
122+
return nil, err
123+
}
124+
125+
for fileName, local := range kubeObjects {
126+
if _, ok := skipUpgradeFor[fileName]; ok {
127+
u.logger.Debug(fmt.Sprintf("Skipping upgrade of %s: should be ignored", fileName))
128+
continue
129+
}
130+
131+
_, _, err := kubeobj.ReplaceObject(kubeClientset, local, opt.ClusterNamespace)
132+
if err != nil {
133+
return nil, err
134+
}
135+
}
136+
137+
return v, nil
138+
}

venonactl/pkg/plugins/plugin.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
RuntimeEnvironmentPluginType = "runtime-environment"
1515
VenonaPluginType = "venona"
1616
VolumeProvisionerPluginType = "volume-provisioner"
17+
EnginePluginType = "engine"
1718
DefaultStorageClassNamePrefix = "dind-local-volumes-venona"
1819
)
1920

@@ -49,7 +50,8 @@ type (
4950
KubeBuilder interface {
5051
BuildClient() (*kubernetes.Clientset, error)
5152
}
52-
DryRun bool
53+
DryRun bool
54+
KubernetesRunnerType bool
5355
}
5456

5557
DeleteOptions struct {
@@ -148,6 +150,12 @@ func build(t string, logger logger.Logger) Plugin {
148150
}
149151
}
150152

153+
if t == EnginePluginType {
154+
return &enginePlugin{
155+
logger: logger.New("Plugin", EnginePluginType),
156+
}
157+
}
158+
151159
return nil
152160
}
153161

venonactl/pkg/plugins/runtime-environment.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ func (u *runtimeEnvironmentPlugin) Install(opt *InstallOptions, v Values) (Value
5151
MarkAsDefault: opt.MarkAsDefault,
5252
StorageClass: opt.StorageClass,
5353
IsDefaultStorageClass: opt.IsDefaultStorageClass,
54+
KubernetesRunnerType: opt.KubernetesRunnerType,
5455
}
56+
5557
cf := codefresh.NewCodefreshAPI(cfOpt)
5658
cert, err := cf.Sign()
5759
if err != nil {

venonactl/pkg/plugins/venona.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (u *venonaPlugin) Install(opt *InstallOptions, v Values) (Values, error) {
7373
namespace: opt.ClusterNamespace,
7474
matchPattern: venonaFilesPattern,
7575
dryRun: opt.DryRun,
76-
operatorType: VolumeProvisionerPluginType,
76+
operatorType: VenonaPluginType,
7777
})
7878
}
7979

@@ -109,7 +109,7 @@ func (u *venonaPlugin) Delete(deleteOpt *DeleteOptions, v Values) error {
109109
kubeClientSet: cs,
110110
namespace: deleteOpt.ClusterNamespace,
111111
matchPattern: venonaFilesPattern,
112-
operatorType: VolumeProvisionerPluginType,
112+
operatorType: VenonaPluginType,
113113
}
114114
return delete(opt)
115115
}

0 commit comments

Comments
 (0)