Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
k8s
devtool
Commits
b4cdb18f
Commit
b4cdb18f
authored
Mar 22, 2019
by
Christopher Harm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Imporving support for config init command
parent
8549a7d4
Pipeline
#29407
passed with stages
in 48 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
8 deletions
+63
-8
cmd/config_init.go
cmd/config_init.go
+63
-8
No files found.
cmd/config_init.go
View file @
b4cdb18f
...
@@ -16,11 +16,14 @@ package cmd
...
@@ -16,11 +16,14 @@ package cmd
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"log"
"log"
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
"git.psu.edu/k8s/devtool/environment"
"git.psu.edu/k8s/devtool/config"
"git.psu.edu/k8s/devtool/config"
"github.com/fatih/color"
"github.com/fatih/color"
...
@@ -85,7 +88,7 @@ var initCmd = &cobra.Command{
...
@@ -85,7 +88,7 @@ var initCmd = &cobra.Command{
dockerfiles
:=
findDockerfiles
()
dockerfiles
:=
findDockerfiles
()
for
_
,
file
:=
range
dockerfiles
{
for
_
,
file
:=
range
dockerfiles
{
color
.
Yellow
(
"Found Dockerfile: %s"
,
file
)
color
.
New
(
color
.
FgYellow
)
.
Printf
(
"Found Dockerfile: %s"
,
file
)
prompt
:=
promptui
.
Prompt
{
prompt
:=
promptui
.
Prompt
{
Label
:
"Include in config"
,
Label
:
"Include in config"
,
Default
:
"Yes"
,
Default
:
"Yes"
,
...
@@ -121,6 +124,7 @@ var initCmd = &cobra.Command{
...
@@ -121,6 +124,7 @@ var initCmd = &cobra.Command{
}
}
deployable
.
Name
=
response
deployable
.
Name
=
response
// Ask for Chart
selectPrompt
:=
promptui
.
SelectWithAdd
{
selectPrompt
:=
promptui
.
SelectWithAdd
{
Label
:
"Chart"
,
Label
:
"Chart"
,
Items
:
[]
string
{
"cm/eio-swe-service"
,
"cm/eio-swe-cronjob"
,
"cm/angular-client"
,
"cm/eio-swe-jms-processor"
},
Items
:
[]
string
{
"cm/eio-swe-service"
,
"cm/eio-swe-cronjob"
,
"cm/angular-client"
,
"cm/eio-swe-jms-processor"
},
...
@@ -132,31 +136,53 @@ var initCmd = &cobra.Command{
...
@@ -132,31 +136,53 @@ var initCmd = &cobra.Command{
}
}
deployable
.
Chart
=
response
deployable
.
Chart
=
response
prompt
=
promptui
.
Prompt
{
// Ask for Chart Version
availableChartVersions
:=
findChartVersions
(
response
)
selectPrompt
=
promptui
.
SelectWithAdd
{
Label
:
"Chart Version"
,
Label
:
"Chart Version"
,
Items
:
availableChartVersions
,
AddLabel
:
"Other"
,
}
}
response
,
err
=
p
rompt
.
Run
()
_
,
response
,
err
=
selectP
rompt
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
deployable
.
ChartVersion
=
response
deployable
.
ChartVersion
=
response
prompt
=
promptui
.
Prompt
{
// Ask for Local Config
availableLocalConfigFiles
:=
findLocalConfigs
()
selectPrompt
=
promptui
.
SelectWithAdd
{
Label
:
"Local Config File"
,
Label
:
"Local Config File"
,
Items
:
availableLocalConfigFiles
,
AddLabel
:
"Other"
,
}
}
response
,
err
=
p
rompt
.
Run
()
_
,
response
,
err
=
selectP
rompt
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
deployable
.
LocalConfig
=
response
deployable
.
LocalConfig
=
response
// Create the file if it doesn't exist already
_
,
err
=
os
.
OpenFile
(
response
,
os
.
O_RDONLY
|
os
.
O_CREATE
,
0666
)
if
err
!=
nil
{
color
.
Yellow
(
"Unable to create config file"
)
}
conf
.
Deployables
=
append
(
conf
.
Deployables
,
deployable
)
conf
.
Deployables
=
append
(
conf
.
Deployables
,
deployable
)
color
.
Green
(
"Adding Deployment"
)
color
.
Green
(
"Adding Deployment"
)
}
}
conf
.
LocalEnvVars
=
[]
string
{
"OAUTH_CLIENT_ID"
}
conf
.
LocalEnvVars
=
[]
string
{
"OAUTH_CLIENT_SECRET"
,
"OAUTH_JWK"
}
color
.
Yellow
(
"Writing configuration"
)
color
.
Yellow
(
"Writing configuration"
)
conf
.
Write
(
configFile
)
err
=
conf
.
Write
(
configFile
)
if
err
!=
nil
{
color
.
New
(
color
.
FgRed
)
.
Printf
(
"Error writing configuration file: %s"
,
configFile
)
}
},
},
}
}
...
@@ -195,3 +221,32 @@ func findDockerfiles() []string {
...
@@ -195,3 +221,32 @@ func findDockerfiles() []string {
}
}
return
dockerfiles
return
dockerfiles
}
}
func
findChartVersions
(
chartName
string
)
[]
string
{
var
versions
[]
string
output
:=
environment
.
RunAndGetOutputRequired
(
"helm"
,
"search"
,
chartName
,
"--versions"
)
for
i
,
line
:=
range
output
{
if
i
==
0
{
continue
}
fields
:=
strings
.
Fields
(
line
)
if
len
(
fields
)
<
4
{
continue
}
versions
=
append
(
versions
,
fields
[
1
])
}
return
versions
}
func
findLocalConfigs
()
[]
string
{
files
,
err
:=
ioutil
.
ReadDir
(
"config/"
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
var
filenames
[]
string
for
_
,
f
:=
range
files
{
filenames
=
append
(
filenames
,
"config/"
+
f
.
Name
())
}
return
filenames
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment