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

AWS provider full refactor #154

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 5 additions & 3 deletions .github/workflows/build-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: '1.20'

- name: Build
run: |
go generate ./...
go build -v ./...

- name: Test
run: go test -v ./...
run: go test -v ./...

# - name: Test
# run: go test -v ./...
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= 0.0.6-dev
VERSION ?= 0.6.0
CONTAINER_MANAGER ?= podman
# Image URL to use all building/pushing image targets
IMG ?= quay.io/rhqp/qenvs:v${VERSION}
Expand Down Expand Up @@ -43,7 +43,7 @@ build: $(BUILD_DIR)/qenvs

.PHONY: test
test:
go test -race --tags build -v -ldflags="$(VERSION_VARIABLES)" ./pkg/... ./cmd/...
CGO_ENABLED=1 go test -race --tags build -v -ldflags="$(VERSION_VARIABLES)" ./pkg/... ./cmd/...

.PHONY: clean ## Remove all build artifacts
clean:
Expand Down Expand Up @@ -73,5 +73,8 @@ oci-push:
.PHONY: tkn-push
tkn-push: install-out-of-tree-tools
$(TOOLS_BINDIR)/tkn bundle push $(TKN_IMG) \
-f tkn/infra-management-aws.yaml \
-f tkn/infra-management-azure.yaml
-f tkn/infra-aws-fedora.yaml \
-f tkn/infra-aws-mac.yaml \
-f tkn/infra-aws-rhel.yaml \
-f tkn/infra-aws-windows-server.yaml \
-f tkn/infra-azure-windows-desktop.yaml
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ automation for qe environments using pulumi

Currently qenvs wil handle offerings on azure and aws the main purpose is offer machines which allows nested virtualization and could be added to a CI/CD system for handling automation on top of them.

* [azure supported environments](docs/azure.md)
* [aws supported environments](docs/aws.md)
* [aws mac](docs/aws/mac.md)
| Platform | Archs | Provider | Type | Information | Tekton |
| -------------- | ------------- | ------------- | ------------- | -------------------------- | -------------------------------------------- |
| Mac | x86, M1, M2 | AWS | Baremetal | [info](docs/aws/mac.md) | [task](tkn/infra-aws-mac.yaml) |
| Windows Server | x86 | AWS | Baremetal | [info](docs/aws/windows.md)| [task](tkn/infra-aws-windows-server.yaml) |
| Windows Desktop| x86 | Azure | Virtualized | [info](docs/azure.md) | [task](tkn/infra-azure-windows-desktop.yaml) |
| RHEL | x86 | AWS | Baremetal | [info](docs/aws/rhel.md) | [task](tkn/infra-aws-rhel.yaml) |
| Fedora | x86 | AWS | Baremetal | [info](docs/aws/fedora.md) | [task](tkn/infra-aws-fedora.yaml) |
13 changes: 5 additions & 8 deletions cmd/cmd/aws/aws.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package aws

import (
"github.com/adrianriobo/qenvs/cmd/cmd/aws/host"
"github.com/adrianriobo/qenvs/cmd/cmd/aws/mac"
"github.com/adrianriobo/qenvs/cmd/cmd/aws/replica"
"github.com/adrianriobo/qenvs/cmd/cmd/aws/spot"
"github.com/adrianriobo/qenvs/cmd/cmd/aws/hosts"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -27,9 +24,9 @@ func GetCmd() *cobra.Command {
}

c.AddCommand(
replica.GetCmd(),
spot.GetCmd(),
host.GetCmd(),
mac.GetCmd())
hosts.GetMacCmd(),
hosts.GetWindowsCmd(),
hosts.GetRHELCmd(),
hosts.GetFedoraCmd())
return c
}
87 changes: 0 additions & 87 deletions cmd/cmd/aws/host/host.go

This file was deleted.

8 changes: 8 additions & 0 deletions cmd/cmd/aws/hosts/constans.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hosts

const (
spot string = "spot"
spotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
airgap string = "airgap"
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"
)
95 changes: 95 additions & 0 deletions cmd/cmd/aws/hosts/fedora.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package hosts

import (
params "github.com/adrianriobo/qenvs/cmd/cmd/constants"
qenvsContext "github.com/adrianriobo/qenvs/pkg/manager/context"
"github.com/adrianriobo/qenvs/pkg/provider/aws/action/fedora"
"github.com/adrianriobo/qenvs/pkg/util/logging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

const (
cmdFedora = "fedora"
cmdFedoraDesc = "manage fedora dedicated host"

fedoraVersion string = "version"
fedoraVersionDesc string = "version for the Fedora Cloud OS"
fedoraVersionDefault string = "39"
)

func GetFedoraCmd() *cobra.Command {
c := &cobra.Command{
Use: cmdFedora,
Short: cmdFedoraDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return nil
},
}
c.AddCommand(getFedoraCreate(), getFedoraDestroy())
return c
}

func getFedoraCreate() *cobra.Command {
c := &cobra.Command{
Use: params.CreateCmdName,
Short: params.CreateCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}

// Initialize context
qenvsContext.Init(
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL),
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags))

// Run create
if err := fedora.Create(
&fedora.Request{
Prefix: "main",
Version: viper.GetString(rhelVersion),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap)}); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
flagSet.StringP(fedoraVersion, "", fedoraVersionDefault, fedoraVersionDesc)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}

func getFedoraDestroy() *cobra.Command {
c := &cobra.Command{
Use: params.DestroyCmdName,
Short: params.DestroyCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}

qenvsContext.InitBase(
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL))

if err := fedora.Destroy(); err != nil {
logging.Error(err)
}
return nil
},
}
return c
}
26 changes: 12 additions & 14 deletions cmd/cmd/aws/mac/mac.go → cmd/cmd/aws/hosts/mac.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mac
package hosts

import (
"fmt"
Expand All @@ -13,16 +13,16 @@ import (
)

const (
cmd = "mac"
cmdDesc = "create mac instances"
cmdMac = "mac"
cmdMacDesc = "manage mac instances"
checkStateCmd = "check-state"
checkStateCmdDesc = "check the state for a dedicated mac machine"

arch string = "arch"
archDesc string = "mac architecture allowed values x86, m1, m2"
archDefault string = "m2"
osVersion string = "version"
osVersionDesc string = "macos operating system vestion 11, 12 on x86 and m1; 13, 14 on all archs"
osVersionDesc string = "macos operating system vestion 11, 12 on x86 and m1/m2; 13, 14 on all archs"
osDefault string = "14"
hostID string = "host-id"
hostIDDesc string = "host id to create the mac instance. If the param is not pass the dedicated host will be created"
Expand All @@ -32,26 +32,24 @@ const (
onlyMachineDesc string = "if this flag is set only the machine will be destroyed"
fixedLocation string = "fixed-location"
fixedLocationDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
airgap string = "airgap"
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"
)

func GetCmd() *cobra.Command {
func GetMacCmd() *cobra.Command {
c := &cobra.Command{
Use: cmd,
Short: cmdDesc,
Use: cmdMac,
Short: cmdMacDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return nil
},
}
c.AddCommand(getCreate(), getDestroy(), getCheckState())
c.AddCommand(getMacCreate(), getMacDestroy(), getMacCheckState())
return c
}

func getCheckState() *cobra.Command {
func getMacCheckState() *cobra.Command {
c := &cobra.Command{
Use: checkStateCmd,
Short: checkStateCmdDesc,
Expand All @@ -77,7 +75,7 @@ func getCheckState() *cobra.Command {
return c
}

func getCreate() *cobra.Command {
func getMacCreate() *cobra.Command {
c := &cobra.Command{
Use: params.CreateCmdName,
Short: params.CreateCmdName,
Expand Down Expand Up @@ -123,7 +121,7 @@ func getCreate() *cobra.Command {
return c
}

func getDestroy() *cobra.Command {
func getMacDestroy() *cobra.Command {
c := &cobra.Command{
Use: params.DestroyCmdName,
Short: params.DestroyCmdName,
Expand All @@ -146,7 +144,7 @@ func getDestroy() *cobra.Command {
return nil
},
}
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(onlyHost, false, onlyHostDesc)
flagSet.Bool(onlyMachine, false, onlyMachineDesc)
c.PersistentFlags().AddFlagSet(flagSet)
Expand Down
Loading