Skip to content

Commit

Permalink
Merge branch 'release/0.35.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ljupcovangelski committed Nov 16, 2021
2 parents af76470 + 29d340e commit b974622
Show file tree
Hide file tree
Showing 182 changed files with 2,165 additions and 2,017 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.34.0
0.35.0
1 change: 1 addition & 0 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6A
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
cloud.google.com/go v0.51.0 h1:PvKAVQWCtlGUSlZkGW3QLelKaWq7KYv/MW1EboG8bfM=
cloud.google.com/go v0.51.0/go.mod h1:hWtGJ6gnXH+KgDv+V0zFGDvpi07n3z8ZNj3T1RW0Gcw=
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
Expand Down
2 changes: 1 addition & 1 deletion cli/integration/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestVersion(t *testing.T) {
}

// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
validVersionString := regexp.MustCompile(`Version: (develop|(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?), GitCommit: [0-9a-f]{5,40}\n$`)
validVersionString := regexp.MustCompile(`CLI version: (develop|(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?), GitCommit: [0-9a-f]{5,40}\n`)

if !validVersionString.MatchString(actual) {
t.Errorf("expected %s to be a valid version but was not", actual)
Expand Down
1 change: 1 addition & 0 deletions cli/pkg/cmd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//cli/pkg/cmd/status",
"//cli/pkg/cmd/ui",
"//cli/pkg/cmd/upgrade",
"//cli/pkg/kube",
"//cli/pkg/workspace",
"@com_github_spf13_cobra//:cobra",
"@com_github_spf13_viper//:viper",
Expand Down
7 changes: 6 additions & 1 deletion cli/pkg/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"cli/pkg/workspace"
"context"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -30,7 +31,11 @@ func applyConfig(cmd *cobra.Command, args []string) {
}

func ApplyConfig(workspacePath string) {
dir := workspace.Init(workspacePath)
dir, err := workspace.Init(workspacePath)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
namespace := viper.GetString("namespace")
conf, err := dir.LoadAiryYaml()
if err != nil {
Expand Down
10 changes: 1 addition & 9 deletions cli/pkg/cmd/create/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "create",
srcs = [
"create.go",
],
srcs = ["create.go"],
importpath = "cli/pkg/cmd/create",
visibility = ["//visibility:public"],
x_defs = {
Expand All @@ -22,12 +20,6 @@ go_library(
"@com_github_spf13_viper//:viper",
"@com_github_twinproduction_go_color//:go-color",
"@in_gopkg_segmentio_analytics_go_v3//:analytics-go_v3",
"@io_k8s_api//batch/v1:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_api//rbac/v1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/watch:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
],
)

Expand Down
32 changes: 30 additions & 2 deletions cli/pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"cli/pkg/cmd/status"
"cli/pkg/cmd/ui"
"cli/pkg/cmd/upgrade"
"cli/pkg/kube"
"cli/pkg/workspace"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -35,7 +36,11 @@ var RootCmd = &cobra.Command{
TraverseChildren: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if cmd.Name() != "create" && cmd.Name() != "version" {
workspace.Init(cliConfigDir)
_, err := workspace.Init(cliConfigDir)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
if !strings.Contains(Version, "alpha") {
cliVersion()
Expand Down Expand Up @@ -73,7 +78,30 @@ var versionCmd = &cobra.Command{
Short: "Prints version information",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s, GitCommit: %s\n", Version, CommitSHA1)
fmt.Printf("CLI version: %s, GitCommit: %s\n", Version, CommitSHA1)

wsPath, _ := cmd.Flags().GetString("workspace")
dir, err := workspace.Init(wsPath)
if err != nil {
return
} else {
dir.LoadAiryYaml()
kubeCtx := kube.Load()
set, err := kubeCtx.GetClientSet()
if err != nil {
fmt.Println("Unable to retrieve the client set:", err.Error())
return
}

coreConfig, err := kube.GetCmData("core-config", viper.GetString("namespace"), set)
if err != nil {
fmt.Println("Unable to retrieve the kubernetes config map:", err.Error())
} else if airyVersion, ok := coreConfig["APP_IMAGE_TAG"]; ok {
fmt.Println("Airy instance version: ", airyVersion)
} else {
fmt.Println("Warning: Unable to retrieve the version of the Airy Core instance from the config map.")
}
}
},
}

Expand Down
18 changes: 12 additions & 6 deletions cli/pkg/cmd/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func status(cmd *cobra.Command, args []string) {
if err != nil {
console.Exit("Could not get kubernetes client", err)
}
cm, _ := clientset.CoreV1().ConfigMaps(viper.GetString("namespace")).Get(context.TODO(), "api-config", v1.GetOptions{})
cm, _ := clientset.CoreV1().ConfigMaps(viper.GetString("namespace")).Get(context.TODO(), "security", v1.GetOptions{})

c.Token = cm.Data["systemToken"]

Expand All @@ -42,13 +42,19 @@ func status(cmd *cobra.Command, args []string) {
}

w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
fmt.Fprintf(w, "service\tenabled\thealthy\n")

for k, v := range res.Components {
if v["enabled"].(bool) {
fmt.Fprintf(w, "%s\t\u2713\n", k)
} else {
fmt.Fprintf(w, "%s\t\u2717\n", k)
for serviceName, service := range res.Services {
enabledStr := "❌"
if service.Enabled {
enabledStr = "✅"
}
healthyStr := "❌"
if service.Healthy {
healthyStr = "✅"
}

fmt.Fprintf(w, "%s\t%s\t%s\n", serviceName, enabledStr, healthyStr)
}

w.Flush()
Expand Down
8 changes: 0 additions & 8 deletions cli/pkg/cmd/upgrade/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@ go_library(
"//cli/pkg/console",
"//cli/pkg/helm",
"//cli/pkg/kube",
"//cli/pkg/providers",
"//cli/pkg/workspace",
"//infrastructure/lib/go/k8s/util",
"@com_github_spf13_cobra//:cobra",
"@com_github_spf13_viper//:viper",
"@com_github_twinproduction_go_color//:go-color",
"@io_k8s_api//batch/v1:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_api//rbac/v1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/watch:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
],
)

Expand Down
7 changes: 6 additions & 1 deletion cli/pkg/cmd/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"cli/pkg/kube"
"cli/pkg/workspace"
"fmt"
"os"

"github.com/airyhq/airy/infrastructure/lib/go/k8s/util"

Expand Down Expand Up @@ -38,7 +39,11 @@ func upgrade(cmd *cobra.Command, args []string) {
if err != nil {
console.Exit("Unable to find suitable workspace :", err)
}
dir := workspace.Init(workspacePath)
dir, err := workspace.Init(workspacePath)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
kubeCtx := kube.Load()
clientset, err := kubeCtx.GetClientSet()
namespace := viper.GetString("namespace")
Expand Down
1 change: 0 additions & 1 deletion cli/pkg/console/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func GetMiddleware(f func(string) string) StdWriter {
func (s StdWriter) Write(p []byte) (int, error) {
_, err := fmt.Print(s.f(string(p)))
if err != nil {
fmt.Print("HNA")
Exit(err)
}
return len(p), err
Expand Down
1 change: 0 additions & 1 deletion cli/pkg/helm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ go_library(
importpath = "cli/pkg/helm",
visibility = ["//visibility:public"],
deps = [
"//cli/pkg/kube",
"//infrastructure/lib/go/k8s/util",
"@io_k8s_api//batch/v1:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (h *Helm) Setup() error {
}

func (h *Helm) InstallCharts() error {
chartURL := "https://airy-core-helm-charts.s3.amazonaws.com/stable/airy-" + h.version + ".tgz"
chartURL := "https://airy-core-helm-charts.s3.amazonaws.com/stable/airy-0.33.0.tgz"
return h.runHelm(append([]string{"install",
"--values", "/apps/config/airy-config-map.yaml",
"--namespace", h.namespace,
Expand Down
3 changes: 1 addition & 2 deletions cli/pkg/kube/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ go_library(
importpath = "cli/pkg/kube",
visibility = ["//visibility:public"],
deps = [
"//cli/pkg/workspace",
"@com_github_spf13_viper//:viper",
"@in_gopkg_yaml_v2//:yaml_v2",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_client_go//kubernetes:go_default_library",
"@io_k8s_client_go//plugin/pkg/client/auth/gcp:go_default_library",
"@io_k8s_client_go//tools/clientcmd:go_default_library",
],
)
2 changes: 2 additions & 0 deletions cli/pkg/kube/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package kube

import (
"errors"

"github.com/spf13/viper"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/clientcmd"
)

Expand Down
18 changes: 8 additions & 10 deletions cli/pkg/workspace/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@ package workspace
import (
"cli/pkg/workspace/template"
"fmt"
"github.com/spf13/viper"
"os"
"path/filepath"

"github.com/spf13/viper"
)

func Init(path string) ConfigDir {
func Init(path string) (ConfigDir, error) {
viper.AddConfigPath(getConfigPath(path))
viper.SetConfigType("yaml")
viper.SetConfigName(cliConfigFileName)

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
fmt.Println(err)
fmt.Println("the current directory is not an airy workspace directory")
err = fmt.Errorf("%w\nthe current directory is not an airy workspace directory", err)
} else {
fmt.Println("invalid configuration: ", err)
err = fmt.Errorf("invalid configuration: %w", err)
}

os.Exit(1)
return ConfigDir{}, err
}

dir := ConfigDir{Path: path}

if _, err := os.Stat(dir.GetAiryYaml()); os.IsNotExist(err) {
fmt.Println("the current directory is not an airy workspace directory")
os.Exit(1)
return dir, fmt.Errorf("the current directory is not an airy workspace directory")
}
return dir
return dir, nil
}

func getConfigPath(path string) string {
Expand All @@ -57,7 +56,6 @@ func Create(path string, data template.Variables) (ConfigDir, error) {
}
}


if err := template.CopyToDir(path, data); err != nil {
return ConfigDir{}, err
}
Expand Down
Loading

0 comments on commit b974622

Please sign in to comment.