Skip to content

Commit

Permalink
Source connections from workspace/deployment (#1414)
Browse files Browse the repository at this point in the history
* Source connections from workspace/deployment

* Working through unit tests

* More

* Temporarily comment out locally-broken test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Test scenarios covered

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix lint issues

* Remove new gitignore file

* empty commit

* add remove to test

* fix lint

* empty commit

* put test back

* fix test

* Fixing test and cleanup test files

* Disable feature by default

* Enable feature for unit tests

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: David Koenitzer <davidkoenit@gmail.com>
Co-authored-by: Kushal Malani <kushal@astronomer.io>
  • Loading branch information
4 people authored Oct 18, 2023
1 parent 89f3604 commit 9c7beba
Show file tree
Hide file tree
Showing 21 changed files with 3,431 additions and 4,241 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VERSION ?= SNAPSHOT-${GIT_COMMIT_SHORT}

LDFLAGS_VERSION=-X github.com/astronomer/astro-cli/version.CurrVersion=${VERSION}

CORE_OPENAPI_SPEC=../astro/apps/core/docs/public/public_v1alpha1.yaml
CORE_OPENAPI_SPEC=../astro/apps/core/docs/public/v1alpha1/public_v1alpha1.yaml

OUTPUT ?= astro
# golangci-lint version
Expand Down Expand Up @@ -39,7 +39,7 @@ core_api_gen:
ifeq (, $(shell which oapi-codegen))
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
endif
oapi-codegen -include-tags=User,Organization,Invite,Workspace,Cluster,Options,Team,ApiToken,Deployment -generate=types,client -package=astrocore "${CORE_OPENAPI_SPEC}" > ./astro-client-core/api.gen.go
oapi-codegen -include-tags=User,Organization,Invite,Workspace,Cluster,Options,Team,ApiToken,Deployment,Environment -generate=types,client -package=astrocore "${CORE_OPENAPI_SPEC}" > ./astro-client-core/api.gen.go
make mock_astro_core

test:
Expand Down
3 changes: 2 additions & 1 deletion airflow/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/astronomer/astro-cli/airflow/types"
"github.com/astronomer/astro-cli/astro-client"
astrocore "github.com/astronomer/astro-cli/astro-client-core"
"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/pkg/fileutil"
"github.com/astronomer/astro-cli/pkg/util"
Expand All @@ -21,7 +22,7 @@ import (
)

type ContainerHandler interface {
Start(imageName, settingsFile, composeFile string, noCache, noBrowser bool, waitTime time.Duration) error
Start(imageName, settingsFile, composeFile string, noCache, noBrowser bool, waitTime time.Duration, envConns map[string]astrocore.EnvironmentObjectConnection) error
Stop(waitForExit bool) error
PS() error
Kill() error
Expand Down
18 changes: 9 additions & 9 deletions airflow/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
semver "github.com/Masterminds/semver/v3"
airflowTypes "github.com/astronomer/astro-cli/airflow/types"
"github.com/astronomer/astro-cli/astro-client"
astrocore "github.com/astronomer/astro-cli/astro-client-core"
"github.com/astronomer/astro-cli/cloud/deployment"
"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/docker"
Expand Down Expand Up @@ -203,7 +204,7 @@ func DockerComposeInit(airflowHome, envFile, dockerfile, imageName string) (*Doc
// Start starts a local airflow development cluster
//
//nolint:gocognit
func (d *DockerCompose) Start(imageName, settingsFile, composeFile string, noCache, noBrowser bool, waitTime time.Duration) error {
func (d *DockerCompose) Start(imageName, settingsFile, composeFile string, noCache, noBrowser bool, waitTime time.Duration, envConns map[string]astrocore.EnvironmentObjectConnection) error {
// check if docker is up for macOS
if runtime.GOOS == "darwin" && config.CFG.DockerCommand.GetString() == dockerCmd {
err := startDocker()
Expand Down Expand Up @@ -300,7 +301,7 @@ func (d *DockerCompose) Start(imageName, settingsFile, composeFile string, noCac
startupTimeout = 5 * time.Minute
}

err = checkWebserverHealth(settingsFile, project, d.composeService, airflowDockerVersion, noBrowser, startupTimeout)
err = checkWebserverHealth(settingsFile, envConns, project, d.composeService, airflowDockerVersion, noBrowser, startupTimeout)
if err != nil {
return err
}
Expand Down Expand Up @@ -1205,7 +1206,7 @@ func (d *DockerCompose) ImportSettings(settingsFile, envFile string, connections
return errNoFile
}

err = initSettings(containerID, settingsFile, airflowDockerVersion, connections, variables, pools)
err = initSettings(containerID, settingsFile, nil, airflowDockerVersion, connections, variables, pools)
if err != nil {
return err
}
Expand Down Expand Up @@ -1365,15 +1366,14 @@ var createDockerProject = func(projectName, airflowHome, envFile, buildImage, se
return project, err
}

var checkWebserverHealth = func(settingsFile string, project *types.Project, composeService api.Service, airflowDockerVersion uint64, noBrowser bool, timeout time.Duration) error {
var checkWebserverHealth = func(settingsFile string, envConns map[string]astrocore.EnvironmentObjectConnection, project *types.Project, composeService api.Service, airflowDockerVersion uint64, noBrowser bool, timeout time.Duration) error {
if config.CFG.DockerCommand.GetString() == podman {
err := printStatus(settingsFile, project, composeService, airflowDockerVersion, noBrowser)
err := printStatus(settingsFile, envConns, project, composeService, airflowDockerVersion, noBrowser)
if err != nil {
if !errors.Is(err, errComposeProjectRunning) {
return err
}
}

} else {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
Expand All @@ -1387,7 +1387,7 @@ var checkWebserverHealth = func(settingsFile string, project *types.Project, com
return err
}
if string(marshal) == `{"action":"health_status: healthy"}` {
err := printStatus(settingsFile, project, composeService, airflowDockerVersion, noBrowser)
err := printStatus(settingsFile, envConns, project, composeService, airflowDockerVersion, noBrowser)
if err != nil {
return err
}
Expand All @@ -1409,7 +1409,7 @@ var checkWebserverHealth = func(settingsFile string, project *types.Project, com
return nil
}

func printStatus(settingsFile string, project *types.Project, composeService api.Service, airflowDockerVersion uint64, noBrowser bool) error {
func printStatus(settingsFile string, envConns map[string]astrocore.EnvironmentObjectConnection, project *types.Project, composeService api.Service, airflowDockerVersion uint64, noBrowser bool) error {
psInfo, err := composeService.Ps(context.Background(), project.Name, api.PsOptions{
All: true,
})
Expand All @@ -1426,7 +1426,7 @@ func printStatus(settingsFile string, project *types.Project, composeService api
for i := range psInfo {
if strings.Contains(psInfo[i].Name, project.Name) &&
strings.Contains(psInfo[i].Name, WebserverDockerContainerName) {
err = initSettings(psInfo[i].ID, settingsFile, airflowDockerVersion, true, true, true)
err = initSettings(psInfo[i].ID, settingsFile, envConns, airflowDockerVersion, true, true, true)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 9c7beba

Please sign in to comment.