Skip to content

Commit

Permalink
Rename Default implementations to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
schnie committed Dec 10, 2024
1 parent ae3fb8d commit f0b5a09
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
6 changes: 3 additions & 3 deletions airflow/runtimes/container_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func GetContainerRuntime() (ContainerRuntime, error) {
// Return the appropriate container runtime based on the binary discovered.
switch containerRuntime {
case docker:
return CreateDockerRuntime(new(DefaultDockerEngine), new(DefaultOSChecker)), nil
return CreateDockerRuntime(new(dockerEngine), new(osChecker)), nil
case podman:
return CreatePodmanRuntime(new(DefaultPodmanEngine), new(DefaultOSChecker)), nil
return CreatePodmanRuntime(new(podmanEngine), new(osChecker)), nil
default:
return nil, errors.New(containerRuntimeNotFoundErrMsg)
}
Expand Down Expand Up @@ -131,7 +131,7 @@ var GetContainerRuntimeBinary = func() (string, error) {
// Get the $PATH environment variable.
pathEnv := os.Getenv("PATH")
for _, binary := range binaries {
if found := FindBinary(pathEnv, binary, new(DefaultOSFileChecker), new(DefaultOSChecker)); found {
if found := FindBinary(pathEnv, binary, CreateOSFileChecker(), CreateOSChecker()); found {
return binary, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion airflow/runtimes/container_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (s *ContainerRuntimeSuite) TestGetContainerRuntimeBinary() {
for _, tt := range tests {
s.Run(tt.name, func() {
mockChecker := mocks.FileChecker{ExistingFiles: tt.mockFiles}
result := FindBinary(tt.pathEnv, tt.binary, mockChecker, new(DefaultOSChecker))
result := FindBinary(tt.pathEnv, tt.binary, mockChecker, new(osChecker))
s.Equal(tt.expected, result)
})
}
Expand Down
9 changes: 4 additions & 5 deletions airflow/runtimes/docker_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ const (
dockerOpenNotice = "We couldn't start the docker engine automatically. Please start it manually and try again."
)

// DefaultDockerEngine is the default implementation of DockerEngine.
// The concrete functions defined here are called from the initializeDocker function below.
type DefaultDockerEngine struct{}
// dockerEngine is the default implementation of DockerEngine.
type dockerEngine struct{}

func (d DefaultDockerEngine) IsRunning() (string, error) {
func (d dockerEngine) IsRunning() (string, error) {
checkDockerCmd := Command{
Command: docker,
Args: []string{
Expand All @@ -22,7 +21,7 @@ func (d DefaultDockerEngine) IsRunning() (string, error) {
return checkDockerCmd.Execute()
}

func (d DefaultDockerEngine) Start() (string, error) {
func (d dockerEngine) Start() (string, error) {
openDockerCmd := Command{
Command: open,
Args: []string{
Expand Down
2 changes: 1 addition & 1 deletion airflow/runtimes/docker_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// DockerEngine is a struct that contains the functions needed to initialize Docker.
// The concrete implementation that we use is DefaultDockerEngine below.
// The concrete implementation that we use is dockerEngine below.
// When running the tests, we substitute the default implementation with a mock implementation.
type DockerEngine interface {
IsRunning() (string, error)
Expand Down
10 changes: 7 additions & 3 deletions airflow/runtimes/file_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ type FileChecker interface {
Exists(path string) bool
}

// DefaultOSFileChecker is a concrete implementation of FileChecker.
type DefaultOSFileChecker struct{}
// osFileChecker is a concrete implementation of FileChecker.
type osFileChecker struct{}

func CreateOSFileChecker() FileChecker {
return new(osFileChecker)
}

// Exists checks if the file exists in the file system.
func (f DefaultOSFileChecker) Exists(path string) bool {
func (f osFileChecker) Exists(path string) bool {
exists, _ := fileutil.Exists(path, nil)
return exists
}
10 changes: 7 additions & 3 deletions airflow/runtimes/os_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ type OSChecker interface {
IsWindows() bool
}

type DefaultOSChecker struct{}
type osChecker struct{}

func CreateOSChecker() OSChecker {
return new(osChecker)
}

// IsWindows is a utility function to determine if the CLI host machine
// is running on Microsoft Windows OS.
func (o DefaultOSChecker) IsWindows() bool {
func (o osChecker) IsWindows() bool {
return runtime.GOOS == "windows"
}

// IsMac is a utility function to determine if the CLI host machine
// is running on Apple macOS.
func (o DefaultOSChecker) IsMac() bool {
func (o osChecker) IsMac() bool {
return runtime.GOOS == "darwin"
}
19 changes: 10 additions & 9 deletions airflow/runtimes/podman_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const (
"Please stop the other machine and try again"
)

type DefaultPodmanEngine struct{}
// podmanEngine is the default implementation of PodmanEngine.
type podmanEngine struct{}

// InitializeMachine initializes our astro Podman machine.
func (e DefaultPodmanEngine) InitializeMachine(name string) error {
func (e podmanEngine) InitializeMachine(name string) error {
// Grab some optional configurations from the config file.
podmanCmd := Command{
Command: podman,
Expand All @@ -47,7 +48,7 @@ func (e DefaultPodmanEngine) InitializeMachine(name string) error {
}

// StartMachine starts our astro Podman machine.
func (e DefaultPodmanEngine) StartMachine(name string) error {
func (e podmanEngine) StartMachine(name string) error {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand All @@ -64,7 +65,7 @@ func (e DefaultPodmanEngine) StartMachine(name string) error {
}

// StopMachine stops the given Podman machine.
func (e DefaultPodmanEngine) StopMachine(name string) error {
func (e podmanEngine) StopMachine(name string) error {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand All @@ -82,7 +83,7 @@ func (e DefaultPodmanEngine) StopMachine(name string) error {

// RemoveMachine removes the given Podman machine completely,
// such that it can only be started again by re-initializing.
func (e DefaultPodmanEngine) RemoveMachine(name string) error {
func (e podmanEngine) RemoveMachine(name string) error {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand All @@ -100,7 +101,7 @@ func (e DefaultPodmanEngine) RemoveMachine(name string) error {
}

// InspectMachine inspects a given podman machine name.
func (e DefaultPodmanEngine) InspectMachine(name string) (*types.InspectedMachine, error) {
func (e podmanEngine) InspectMachine(name string) (*types.InspectedMachine, error) {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand All @@ -127,7 +128,7 @@ func (e DefaultPodmanEngine) InspectMachine(name string) (*types.InspectedMachin
}

// SetMachineAsDefault sets the given Podman machine as the default.
func (e DefaultPodmanEngine) SetMachineAsDefault(name string) error {
func (e podmanEngine) SetMachineAsDefault(name string) error {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand All @@ -145,7 +146,7 @@ func (e DefaultPodmanEngine) SetMachineAsDefault(name string) error {
}

// ListMachines lists all Podman machines.
func (e DefaultPodmanEngine) ListMachines() ([]types.ListedMachine, error) {
func (e podmanEngine) ListMachines() ([]types.ListedMachine, error) {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand All @@ -168,7 +169,7 @@ func (e DefaultPodmanEngine) ListMachines() ([]types.ListedMachine, error) {
}

// ListContainers lists all pods in the machine.
func (e DefaultPodmanEngine) ListContainers() ([]types.ListedContainer, error) {
func (e podmanEngine) ListContainers() ([]types.ListedContainer, error) {
podmanCmd := Command{
Command: podman,
Args: []string{
Expand Down
2 changes: 1 addition & 1 deletion cmd/airflow_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func EnsureRuntime(cmd *cobra.Command, args []string) error {
// Check if the OS is Windows and create the plugins project directory if it doesn't exist.
// In Windows, the compose project will fail if the plugins directory doesn't exist, due
// to the volume mounts we specify.
osChecker := new(runtimes.DefaultOSChecker)
osChecker := runtimes.CreateOSChecker()
if osChecker.IsWindows() {
pluginsDir := filepath.Join(config.WorkingPath, "plugins")
if err := os.MkdirAll(pluginsDir, os.ModePerm); err != nil && !os.IsExist(err) {
Expand Down

0 comments on commit f0b5a09

Please sign in to comment.