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

add azure fedora support #298

Merged
merged 4 commits into from
Sep 30, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Also mapt offers a set of features wich are transversal to each type of target m
| RHEL | x86, arm64 | AWS | Customizable | [info](docs/aws/rhel.md) | [task](tkn/infra-aws-rhel.yaml) | a,s |
| RHEL | x86, arm64 | Azure | Virtualized | [info](docs/azure/rhel.md) | [task](tkn/infra-azure-rhel.yaml) | s |
| Fedora | x86, arm64 | AWS | Customizable | [info](docs/aws/fedora.md) | [task](tkn/infra-aws-fedora.yaml) | a,s |
| Fedora | x86, arm64 | Azure | Customizable | [info](docs/azure/fedora.md) | [task](tkn/infra-azure-fedora.yaml) | a,s |
| Ubuntu | x86 | Azure | Virtualized | [info](docs/azure/ubuntu.md) | - | s |

Features:
Expand Down
1 change: 1 addition & 0 deletions cmd/mapt/cmd/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func GetCmd() *cobra.Command {
hosts.GetWindowsDesktopCmd(),
hosts.GetUbuntuCmd(),
hosts.GetRHELCmd(),
hosts.GetFedoraCmd(),
services.GetAKSCmd())
return c
}
11 changes: 9 additions & 2 deletions cmd/mapt/cmd/azure/hosts/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ const (
cmdUbuntu = "ubuntu"
cmdUbuntuDesc = "ubuntu operations"
cmdRHEL = "rhel"
cmdRHELDesc = "ubuntu operations"
cmdRHELDesc = "RHEL operations"
cmdFedora = "fedora"
cmdFedoraDesc = "fedora operations"
defaultVMSize = "Standard_D8as_v5"

paramLinuxVersion = "version"
paramLinuxVersionDesc = "linux version. Version should be formmated as X.Y (Major.minor)"
paramLinuxVersionDesc = "linux version. Version should be formated as X.Y (Major.minor)"
defaultUbuntuVersion = "24.04"
defaultRHELVersion = "9.4"
defaultFedoraVersion = "40.0"
)

func GetUbuntuCmd() *cobra.Command {
Expand All @@ -38,6 +41,10 @@ func GetRHELCmd() *cobra.Command {
return getLinuxCmd(cmdRHEL, cmdRHELDesc, azureLinux.RHEL, defaultRHELVersion)
}

func GetFedoraCmd() *cobra.Command {
return getLinuxCmd(cmdFedora, cmdFedoraDesc, azureLinux.Fedora, defaultFedoraVersion)
}

func getLinuxCmd(cmd, cmdDesc string, ostype azureLinux.OSType, defaultOSVersion string) *cobra.Command {
c := &cobra.Command{
Use: cmd,
Expand Down
87 changes: 87 additions & 0 deletions docs/azure/fedora.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Overview

mapt offers several operations to manage environments within azure:

## Fedora

It creates / destroy a Fedora machine ready to be included within the CI/CD system. Features included within the offering:

* Setup ssh for the user user with a self generated private key

### Operations

#### Create

This will create a fedora instance accordig to params specificed:

```bash
podman run -it --rm quay.io/redhat-developer/mapt:0.7.0-dev azure fedora create -h
create

Usage:
mapt azure fedora create [flags]

Flags:
--arch string architecture for the machine. Allowed x86_64 or arm64 (default "x86_64")
--conn-details-output string path to export host connection information (host, username and privateKey)
--cpus int32 Number of CPUs for the cloud instance (default 8)
-h, --help help for create
--location string If spot is passed location will be calculated based on spot results. Otherwise localtion will be used to create resources. (default "West US")
--memory int32 Amount of RAM for the cloud instance in GiB (default 64)
--nested-virt Use cloud instance that has nested virtualization support
--spot if spot is set the spot prices across all regions will be cheked and machine will be started on best spot option (price / eviction)
--spot-eviction-tolerance string if spot is enable we can define the minimum tolerance level of eviction. Allowed value are: lowest, low, medium, high or highest (default "lowest")
--tags stringToString tags to add on each resource (--tags name1=value1,name2=value2) (default [])
--username string username for general user. SSH accessible + rdp with generated password (default "rhqp")
--version string linux version. Version should be formated as X.Y (Major.minor)
--vmsize strings set specific size for the VM and ignore any CPUs, Memory and Arch parameters set. Type requires to allow nested virtualization

Global Flags:
--backed-url string backed for stack state. Can be a local path with format file:///path/subpath or s3 s3://existing-bucket
--project-name string project name to identify the instance of the stack
```
> *NOTE:* Fedora distro version needs to be in the form x.y, but official fedora versions contain just the major version. For fedora 40 use `--version 40.0`

> *NOTE:* You can list all the available fedora images using `az`, please refer: https://fedoramagazine.org/launch-fedora-40-in-microsoft-azure for more information

It will crete a fedora instance and will give as result several files located at path defined by `--conn-details-output`:


* username: file containing the username for worker user
* id_rsa: file containing the private key for worker user
* host: file containing the public ip for the instance

Also it will create a state folder holding the state for the created resources at azure, the path for this folder is defined within `--backed-url`, the content from that folder it is required with the same project name (`--project-name`) in order to detroy the resources.

When running the container image it is required to pass the authetication information as variables, following a sample snipped on how to create
a instance with default values:

```bash
podman run -d --rm \
-v ${PWD}:/workspace:z \
-e ARM_TENANT_ID=${ati_value} \
-e ARM_SUBSCRIPTION_ID=${asi_value} \
-e ARM_CLIENT_ID=${aci_value} \
-e ARM_CLIENT_SECRET=${acs_lue} \
quay.io/redhat-developer/mapt:0.7.0-dev azure \
fedora create \
--project-name "fedora-40" \
--backed-url "file:///workspace" \
--conn-details-output "/workspace" \
--spot
```

The following is a snippet on how to destroy the resources:

```bash
podman run -d --rm \
-v ${PWD}:/workspace:z \
-e ARM_TENANT_ID=${ati_value} \
-e ARM_SUBSCRIPTION_ID=${asi_value} \
-e ARM_CLIENT_ID=${aci_value} \
-e ARM_CLIENT_SECRET=${acs_lue} \
quay.io/redhat-developer/mapt:0.7.0-dev azure \
fedora destroy \
--project-name "fedora-40" \
--backed-url "file:///workspace"
```
16 changes: 16 additions & 0 deletions pkg/provider/azure/action/linux/imageref.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ const (
Fedora
)

const fedoraImageGalleryBase = "/CommunityGalleries/Fedora-5e266ba4-2250-406d-adad-5d73860d958f/Images/"

type imageReference struct {
publisher string
offer string
sku string
// community gallery image ID
id string
}

var (
Expand All @@ -40,6 +44,14 @@ var (
sku: "server",
},
},
Fedora: {
"x86_64": {
id: fedoraImageGalleryBase + "Fedora-Cloud-%s-x64/Versions/latest",
},
"arm64": {
id: fedoraImageGalleryBase + "Fedora-Cloud-%s-Arm64/Versions/latest",
},
},
}
)

Expand All @@ -60,6 +72,10 @@ func getImageRef(osTarget OSType, arch string, version string) (*imageReference,
offer: ir.offer,
sku: fmt.Sprintf(ir.sku, versions[0], versions[1]),
}, nil
case Fedora:
return &imageReference{
id: fmt.Sprintf(ir.id, versions[0]),
}, nil
}
return nil, fmt.Errorf("os type not supported")

Expand Down
14 changes: 3 additions & 11 deletions pkg/provider/azure/action/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/redhat-developer/mapt/pkg/provider/util/command"
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
"github.com/redhat-developer/mapt/pkg/provider/util/output"
"github.com/redhat-developer/mapt/pkg/util"
spotAzure "github.com/redhat-developer/mapt/pkg/spot/azure"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/logging"
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
)
Expand Down Expand Up @@ -46,16 +46,6 @@ type LinuxRequest struct {
SpotTolerance spotAzure.EvictionRate
}

type UbuntuRequest struct {
Prefix string
Location string
VMSize string
Version string
Username string
Spot bool
SpotTolerance spotAzure.EvictionRate
}

func Create(r *LinuxRequest) (err error) {
if len(r.VMSizes) == 0 {
vmSizes, err := r.InstanceRequest.GetMachineTypes()
Expand Down Expand Up @@ -130,6 +120,7 @@ func (r *LinuxRequest) deployer(ctx *pulumi.Context) error {
if err != nil {
return err
}

vmr := virtualmachine.VirtualMachineRequest{
Prefix: r.Prefix,
ComponentID: azureLinuxID,
Expand All @@ -139,6 +130,7 @@ func (r *LinuxRequest) deployer(ctx *pulumi.Context) error {
Publisher: ir.publisher,
Offer: ir.offer,
Sku: ir.sku,
ImageID: ir.id,
AdminUsername: r.Username,
PrivateKey: privateKey,
SpotPrice: spotPrice,
Expand Down
21 changes: 15 additions & 6 deletions pkg/provider/azure/module/virtual-machine/virtual-machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type VirtualMachineRequest struct {
Offer string
Sku string
SpotPrice *float64
// community galary image ID
ImageID string
// Windows required
AdminUsername string
// Linux required
Expand All @@ -38,6 +40,18 @@ type VirtualMachineRequest struct {
// Create virtual machine based on request + export to context
// adminusername and adminuserpassword
func (r *VirtualMachineRequest) Create(ctx *pulumi.Context) (*compute.VirtualMachine, error) {
var imageReferenceArgs compute.ImageReferenceArgs
if len(r.ImageID) > 0 {
imageReferenceArgs = compute.ImageReferenceArgs{
CommunityGalleryImageId: pulumi.String(r.ImageID)}
} else {
imageReferenceArgs = compute.ImageReferenceArgs{
Publisher: pulumi.String(r.Publisher),
Offer: pulumi.String(r.Offer),
Sku: pulumi.String(r.Sku),
Version: pulumi.String("latest"),
}
}
vmArgs := &compute.VirtualMachineArgs{
VmName: pulumi.String(maptContext.RunID()),
Location: r.ResourceGroup.Location,
Expand All @@ -53,12 +67,7 @@ func (r *VirtualMachineRequest) Create(ctx *pulumi.Context) (*compute.VirtualMac
VmSize: pulumi.String(r.VMSize),
},
StorageProfile: compute.StorageProfileArgs{
ImageReference: compute.ImageReferenceArgs{
Publisher: pulumi.String(r.Publisher),
Offer: pulumi.String(r.Offer),
Sku: pulumi.String(r.Sku),
Version: pulumi.String("latest"),
},
ImageReference: imageReferenceArgs,
OsDisk: compute.OSDiskArgs{
Name: pulumi.String(maptContext.RunID()),
DiskSizeGB: pulumi.Int(diskSize),
Expand Down
Loading