Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source connections from workspace/deployment #1414

Merged
merged 20 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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