Skip to content

Commit

Permalink
Merge branch 'main' into release-0.25
Browse files Browse the repository at this point in the history
  • Loading branch information
bote795 committed Sep 15, 2021
2 parents e95011f + 0e9402a commit dbf5536
Show file tree
Hide file tree
Showing 22 changed files with 572 additions and 30 deletions.
10 changes: 8 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ brews:
owner: astronomer
name: homebrew-tap
folder: Formula
# Setting this will prevent goreleaser to actually try to commit the updated
# formula - instead, the formula file will be stored on the dist folder only,
# leaving the responsibility of publishing it to the user.
# If set to auto, the release will not be uploaded to the homebrew tap
# in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
# Default is false.
skip_upload: true
homepage: https://astronomer.io
description: To build and run Airflow DAGs locally via docker-compose and deploy DAGs to Astronomer-managed Airflow clusters and interact with the Astronomer API.
test: |
system "#{bin}/astro version"
archives:
-
format: tar.gz
- format: tar.gz
format_overrides:
- goos: windows
format: zip
Expand Down
2 changes: 2 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@
[[constraint]]
name = "github.com/moby/buildkit"
version = "0.6.3"

[[constraint]]
name = "github.com/sirupsen/logrus"
version = "v1.0.3"
3 changes: 3 additions & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/astronomer/astro-cli/pkg/input"
"github.com/astronomer/astro-cli/workspace"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

// basicAuth handles authentication with the houston api
Expand Down Expand Up @@ -171,6 +172,8 @@ func Login(domain string, oAuthOnly bool, username, password string, client *hou

err = registryAuth()
if err != nil {
log.Debugf("There was an error logging into registry: %s", err.Error())

fmt.Printf(messages.RegistryAuthFail)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func newDeploymentListCmd(client *houston.Client, out io.Writer) *cobra.Command
}

func newDeploymentUpdateCmd(client *houston.Client, out io.Writer) *cobra.Command {
example := `
example := `
# update labels and description for given deployment
$ astro deployment update UUID label=Production-Airflow description=example version=v1.0.0`
updateExampleDagDeployment := `
Expand Down
22 changes: 22 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package cmd
import (
"io"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/houston"
"github.com/astronomer/astro-cli/version"
)
Expand All @@ -15,6 +17,7 @@ var (
deploymentRole string
role string
skipVerCheck bool
verboseLevel string
)

// NewRootCmd adds all of the primary commands for the cli
Expand All @@ -24,11 +27,15 @@ func NewRootCmd(client *houston.Client, out io.Writer) *cobra.Command {
Short: "Astronomer - CLI",
Long: "astro is a command line interface for working with the Astronomer Platform.",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := SetUpLogs(out, verboseLevel); err != nil {
return err
}
return version.ValidateCompatibility(client, out, version.CurrVersion, skipVerCheck)
},
}

rootCmd.PersistentFlags().BoolVarP(&skipVerCheck, "skip-version-check", "", false, "skip version compatibility check")
rootCmd.PersistentFlags().StringVarP(&verboseLevel, "verbosity", "", logrus.WarnLevel.String(), "Log level (debug, info, warn, error, fatal, panic")
rootCmd.AddCommand(
newAuthRootCmd(client, out),
newWorkspaceCmd(client, out),
Expand All @@ -48,3 +55,18 @@ func NewRootCmd(client *houston.Client, out io.Writer) *cobra.Command {
)
return rootCmd
}

// setUpLogs set the log output and the log level
func SetUpLogs(out io.Writer, level string) error {
// if level is default means nothing was passed override with config setting
if level == "warning" {
level = config.CFG.Verbosity.GetString()
}
logrus.SetOutput(out)
lvl, err := logrus.ParseLevel(level)
if err != nil {
return err
}
logrus.SetLevel(lvl)
return nil
}
13 changes: 13 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"os"
"testing"

testUtil "github.com/astronomer/astro-cli/pkg/testing"
Expand All @@ -13,3 +14,15 @@ func TestRootCommand(t *testing.T) {
assert.NoError(t, err)
assert.Contains(t, output, "astro [command]")
}

func TestSetupLogsDefault(t *testing.T) {
testUtil.InitTestConfig()
err := SetUpLogs(os.Stdout, "warning")
assert.NoError(t, err)
}

func TestSetupLogsDebug(t *testing.T) {
testUtil.InitTestConfig()
err := SetUpLogs(os.Stdout, "debug")
assert.NoError(t, err)
}
21 changes: 11 additions & 10 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ coverage:
precision: 2

status:
project: # measuring the overall project coverage
default: # context, you can create multiple ones with custom titles
enabled: yes # must be yes|true to enable this status
target: 55 # specify the target coverage for each commit status
# option: "auto" (must increase from parent commit or pull request base)
# option: "X%" a static target percentage to hit
if_not_found: success # if parent is not found report status as success, error, or failure
if_ci_failed: error # if ci fails report status as success, error, or failure
project: # measuring the overall project coverage
default: # context, you can create multiple ones with custom titles
enabled: yes # must be yes|true to enable this status
target:
55 # specify the target coverage for each commit status
# option: "auto" (must increase from parent commit or pull request base)
# option: "X%" a static target percentage to hit
if_not_found: success # if parent is not found report status as success, error, or failure
if_ci_failed: error # if ci fails report status as success, error, or failure
patch:
default:
enabled: yes
target: auto
threshold: 1% # allowed to drop X% and still result in a "success" commit status
base: auto
threshold: 1% # allowed to drop X% and still result in a "success" commit status
base: 55.55
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var (
ShowWarnings: newCfg("show_warnings", "true"),
AirflowReleasesURL: newCfg("airflow_releases_url", "https://updates.astronomer.io/astronomer-certified"),
SkipVerifyTLS: newCfg("skip_verify_tls", "false"),
Verbosity: newCfg("verbosity", "warning"),
}

// viperHome is the viper object in the users home directory
Expand Down
1 change: 1 addition & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type cfgs struct {
ShowWarnings cfg
AirflowReleasesURL cfg
SkipVerifyTLS cfg
Verbosity cfg
}

// Creates a new cfg struct
Expand Down
73 changes: 73 additions & 0 deletions deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strconv"

"github.com/Masterminds/semver"
"github.com/sirupsen/logrus"

"github.com/astronomer/astro-cli/houston"
"github.com/astronomer/astro-cli/pkg/input"
Expand Down Expand Up @@ -39,6 +40,7 @@ func AppVersion(client *houston.Client) (*houston.AppConfig, error) {

// AppConfig returns application config from houston-api
func AppConfig(client *houston.Client) (*houston.AppConfig, error) {
logrus.Debug("Checking AppConfig from houston-api")
req := houston.Request{
Query: houston.AppConfigRequest,
}
Expand All @@ -51,6 +53,7 @@ func AppConfig(client *houston.Client) (*houston.AppConfig, error) {
}

func checkManualReleaseNames(client *houston.Client) bool {
logrus.Debug("Checking checkManualReleaseNames through appConfig from houston-api")
req := houston.Request{
Query: houston.AppConfigRequest,
}
Expand All @@ -64,6 +67,7 @@ func checkManualReleaseNames(client *houston.Client) bool {

// CheckNFSMountDagDeployment returns true when we can set custom NFS location for dags
func CheckNFSMountDagDeployment(client *houston.Client) bool {
logrus.Debug("Checking checkNFSMountDagDeployment through appConfig from houston-api")
req := houston.Request{
Query: houston.AppConfigRequest,
}
Expand All @@ -76,17 +80,35 @@ func CheckNFSMountDagDeployment(client *houston.Client) bool {
}

func CheckHardDeleteDeployment(client *houston.Client) bool {
logrus.Debug("Checking for hard delete deployment flag")
appConfig, err := AppConfig(client)
if err != nil {
return false
}
return appConfig.HardDeleteDeployment
}

func CheckPreCreateNamespaceDeployment(client *houston.Client) bool {
logrus.Debug("Checking for pre created deployment flag")
appConfig, err := AppConfig(client)
if err != nil {
return false
}
return appConfig.ManualNamespaceNames
}

// Create airflow deployment
func Create(label, ws, releaseName, cloudRole, executor, airflowVersion, dagDeploymentType, nfsLocation string, client *houston.Client, out io.Writer) error {
vars := map[string]interface{}{"label": label, "workspaceId": ws, "executor": executor, "cloudRole": cloudRole}

if CheckPreCreateNamespaceDeployment(client) {
namespace, err := getDeploymentSelectionNamespaces(client, out)
if err != nil {
return err
}
vars["namespace"] = namespace
}

if releaseName != "" && checkManualReleaseNames(client) {
vars["releaseName"] = releaseName
}
Expand Down Expand Up @@ -163,6 +185,57 @@ func Delete(id string, hardDelete bool, client *houston.Client, out io.Writer) e
return nil
}

// list all available namespaces
func getDeploymentSelectionNamespaces(client *houston.Client, out io.Writer) (string, error) {

tab := &printutil.Table{
Padding: []int{30},
DynamicPadding: true,
Header: []string{"AVAILABLE KUBERNETES NAMESPACES"},
}

logrus.Debug("checking namespaces available for platform")
tab.GetUserInput = true

req := houston.Request{
Query: houston.AvailableNamespacesGetRequest,
}

r, err := req.DoWithClient(client)
if err != nil {
return "", err
}

names := r.Data.GetDeploymentNamespaces

if len(names) == 0 {
return "", errors.New("no kubernetes namespaces are available")
}

for _, namespace := range names {
name := namespace.Name

tab.AddRow([]string{name}, false)
}

tab.Print(out)

in := input.InputText("\n> ")
i, err := strconv.ParseInt(
in,
10,
64,
)

if err != nil {
return "", fmt.Errorf("cannot parse %s to int", in)
}
if i > int64(len(names)) {
return "", errors.New("Number is out of available range")
}
return names[i-1].Name, nil
}

// List all airflow deployments
func List(ws string, all bool, client *houston.Client, out io.Writer) error {
var deployments []houston.Deployment
Expand Down
Loading

0 comments on commit dbf5536

Please sign in to comment.