Commit 7c1cc6b0 authored by Christopher Harm's avatar Christopher Harm

Fixing logging and adding kubectl config

parent b4cdb18f
Pipeline #29410 passed with stages
in 55 seconds
......@@ -46,7 +46,7 @@ var buildCmd = &cobra.Command{
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).PrintFunc()("Error reading configuration file: %s", configFile)
color.New(color.FgRed).Printf("Error reading configuration file: %s\n", configFile)
return
}
......@@ -102,7 +102,7 @@ func build(config config.Config) error {
case "go":
environment.RunRequired(true, "make", "build")
default:
color.New(color.FgRed).PrintFunc()("devtool doesn't support the '%s' language yet.", lang)
color.New(color.FgRed).Printf("devtool doesn't support the '%s' language yet.\n", lang)
return errors.New("Language not supported")
}
return nil
......@@ -128,7 +128,7 @@ func buildDockerAndDeploy(config config.Config) error {
fmt.Println(dockerRootDir)
}
color.New(color.FgGreen).PrintFunc()("Building ", dockerTag)
color.New(color.FgGreen).Printf("Building: %s\n", dockerTag)
err = environment.Run(true, "docker", "build", "-t", dockerTag, "-f", dockerfile, dockerRootDir)
if err != nil {
return err
......@@ -154,12 +154,15 @@ func buildDockerAndDeploy(config config.Config) error {
err = environment.Run(true, "helm", args...)
if err != nil {
color.New(color.FgRed).PrintFunc()("helm error. try running 'helm del --purge %s'", releaseName)
color.New(color.FgRed).Printf("helm error. try running 'helm del --purge %s'\n", releaseName)
return err
}
if openServices {
environment.Run(true, "minikube", "service", releaseName)
err = environment.Run(true, "minikube", "service", releaseName)
if err != nil {
return err
}
}
}
return nil
......
......@@ -41,7 +41,10 @@ func init() {
ciCmd.PersistentFlags().StringVarP(&imageTag, "image-tag", "i", "", "image tag for docker")
ciCmd.PersistentFlags().StringVarP(&environmentSuffix, "environment", "e", "", "environment suffix to append to helm release name")
ciCmd.MarkPersistentFlagRequired("image-tag")
err := ciCmd.MarkPersistentFlagRequired("image-tag")
if err != nil {
panic("invalid arg")
}
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
......
......@@ -31,7 +31,7 @@ var ciBuildCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).PrintFunc()("Error reading configuration file: %s", configFile)
color.New(color.FgRed).Printf("Error reading configuration file: %s\n", configFile)
return err
}
......@@ -59,8 +59,14 @@ func init() {
ciBuildCmd.Flags().StringVarP(&dockerRegistry, "registry", "r", "", "url of the docker registry")
ciBuildCmd.Flags().StringVarP(&dockerRegistryNamespace, "registry-namespace", "n", "", "namespace in the docker registry")
ciBuildCmd.MarkFlagRequired("registry")
ciBuildCmd.MarkFlagRequired("registry-namespace")
err := ciBuildCmd.MarkFlagRequired("registry")
if err != nil {
panic("invalid arg")
}
err = ciBuildCmd.MarkFlagRequired("registry-namespace")
if err != nil {
panic("invalid arg")
}
}
func buildCiDocker(config config.Config) error {
......@@ -73,13 +79,13 @@ func buildCiDocker(config config.Config) error {
dockerImage := dockerRegistry + "/" + dockerRegistryNamespace + "/" + image
dockerTag := dockerImage + ":" + imageTag
color.New(color.FgGreen).PrintFunc()("Building: ", dockerTag)
color.New(color.FgGreen).Printf("Building: %s\n", dockerTag)
err := environment.Run(true, "docker", "build", "-t", dockerTag, "-f", dockerfile, ".")
if err != nil {
return err
}
color.New(color.FgGreen).PrintFunc()("Pushing Docker image: ", dockerTag)
color.New(color.FgGreen).Printf("Pushing Docker image: %s\n", dockerTag)
err = environment.Run(true, "docker", "push", dockerImage)
if err != nil {
return err
......
......@@ -30,7 +30,7 @@ var ciDeployCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).PrintFunc()("Error reading configuration file: %s", configFile)
color.New(color.FgRed).Printf("Error reading configuration file: %s\n", configFile)
return err
}
......@@ -69,14 +69,14 @@ func fluxDeployCi(config config.Config) error {
} else {
releaseName = deployable.Name + "-" + environmentSuffix
}
color.Blue("Updating Flux Release:" + releaseName)
color.New(color.FgBlue).Printf("Updating Flux Release: %s\n", releaseName)
os.Setenv("KUBE_SERVICE_NAME", releaseName)
os.Setenv("CI_PROJECT_NAME", image)
err := environment.Run(true, "fluxhelmrelease")
if err != nil {
color.Red("fluxhelmrelease error.")
color.Red("fluxhelmrelease error: %s", err)
return err
}
}
......
......@@ -88,7 +88,7 @@ var initCmd = &cobra.Command{
dockerfiles := findDockerfiles()
for _, file := range dockerfiles {
color.New(color.FgYellow).Printf("Found Dockerfile: %s", file)
color.New(color.FgYellow).Printf("Found Dockerfile: %s\n", file)
prompt := promptui.Prompt{
Label: "Include in config",
Default: "Yes",
......@@ -181,7 +181,7 @@ var initCmd = &cobra.Command{
err = conf.Write(configFile)
if err != nil {
color.New(color.FgRed).Printf("Error writing configuration file: %s", configFile)
color.New(color.FgRed).Printf("Error writing configuration file: %s\n", configFile)
}
},
......
......@@ -29,7 +29,7 @@ var listCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgRed).PrintFunc()("Error reading configuration file: ", configFile, "\n")
color.New(color.FgRed).Printf("Error reading configuration file: %s\n", configFile)
return
}
fmt.Println("Project Configuration")
......
......@@ -36,7 +36,7 @@ var runCmd = &cobra.Command{
conf, err := config.New(configFile)
if err != nil {
color.New(color.FgYellow).PrintfFunc()("WARNING: no project configuration exists: %s\n", configFile)
color.New(color.FgYellow).Printf("WARNING: no project configuration exists: %s\n", configFile)
}
localConfig := selectLocalConfig(conf.Deployables)
......@@ -45,7 +45,7 @@ var runCmd = &cobra.Command{
var helmValues config.HelmValues
helmValues, err = config.ReadHelmValues(localConfig)
if err != nil {
color.Red("Error reading local config file: " + localConfig)
color.New(color.FgRed).Printf("Error reading local config file: %s\n", localConfig)
}
for k, v := range helmValues.EnvironmentVariables {
os.Setenv(k, v)
......@@ -70,7 +70,10 @@ func init() {
// is called directly, e.g.:
runCmd.Flags().StringVarP(&command, "command", "c", "", "The command to run")
runCmd.MarkFlagRequired("command")
err := runCmd.MarkFlagRequired("command")
if err != nil {
panic("invalid arg")
}
}
func selectLocalConfig(deployables []config.Deployable) string {
......
......@@ -16,7 +16,6 @@ package cmd
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
......@@ -78,15 +77,9 @@ func start(memory, cpu string) {
environment.RunRequired(true, "minikube", "start", "--memory", memory, "--cpus", cpu)
}
checkInstallTiller()
environment.EvalDockerEnv()
fixKubectlContext()
color.Blue("Environment Variables:")
for _, e := range os.Environ() {
fmt.Println(e)
}
checkInstallTiller()
}
......@@ -113,13 +106,31 @@ func checkLocalSetup() bool {
func checkInstalled(app string) error {
path, err := exec.LookPath(app)
if err != nil {
color.New(color.FgYellow).PrintfFunc()("%s is not installed\n", app)
color.New(color.FgYellow).Printf("%s is not installed\n", app)
} else {
fmt.Printf("%s: %s\n", app, path)
}
return err
}
func fixKubectlContext() {
color.Blue("setting kubectl context.")
_, err := exec.LookPath("kubectx")
if err != nil {
color.New(color.FgYellow).Printf("kubectx is not installed")
} else {
environment.RunRequired(true, "kubectx", "minikube")
}
_, err = exec.LookPath("kubens")
if err != nil {
color.New(color.FgYellow).Printf("kubens is not installed")
} else {
environment.RunRequired(true, "kubens", "default")
}
}
func checkInstallTiller() {
color.Blue("Checking if Tiller is installed.")
......@@ -133,15 +144,18 @@ func checkInstallTiller() {
time.Sleep(10 * time.Second)
serverVersionOutput, err = environment.RunAndGetOutput("helm", "version", "--server", "--short")
if err != nil {
color.Red("Cannot determin helm server version")
}
}
clientVersion := strings.TrimPrefix(clientVersionOutput[0], "Client: ")
serverVersion := strings.TrimPrefix(serverVersionOutput[0], "Server: ")
if clientVersion != serverVersion {
warn := color.New(color.FgYellow).PrintFunc()
warn("Helm version mismatch between client and server")
warn("Client Version: %s\n", clientVersion)
warn("Server Version: %s\n", serverVersion)
warn := color.New(color.FgYellow).PrintfFunc()
warn("Helm version mismatch between client and server\n")
warn(" Client Version: %s\n", clientVersion)
warn(" Server Version: %s\n", serverVersion)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment