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

WIP: add ore command to create azure gallery #523

Draft
wants to merge 19 commits into
base: flatcar-master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Execute(main *cobra.Command) {
"Alias for --log-level=DEBUG")

WrapPreRun(main, func(cmd *cobra.Command, args []string) error {
startLogging(cmd)
StartLogging(cmd)
return nil
})

Expand All @@ -78,7 +78,7 @@ func setRepoLogLevel(repo string, l capnslog.LogLevel) {
r.SetRepoLogLevel(l)
}

func startLogging(cmd *cobra.Command) {
func StartLogging(cmd *cobra.Command) {
switch {
case logDebug:
logLevel = capnslog.DEBUG
Expand Down
6 changes: 2 additions & 4 deletions cmd/kola/kola.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,11 @@ func runRun(cmd *cobra.Command, args []string) {

// needs to be after RunTests() because harness empties the directory
if err := writeProps(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
plog.Fatal(err)
}

if runErr != nil {
fmt.Fprintf(os.Stderr, "%v\n", runErr)
os.Exit(1)
plog.Fatal(runErr)
}
}

Expand Down
1 change: 1 addition & 0 deletions cmd/kola/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func init() {
sv(&kola.AzureOptions.ResourceGroup, "azure-resource-group", "", "Deploy resources in an existing resource group")
sv(&kola.AzureOptions.AvailabilitySet, "azure-availability-set", "", "Deploy instances with an existing availibity set")
sv(&kola.AzureOptions.KolaVnet, "azure-kola-vnet", "", "Pass the vnet/subnet that kola is being ran from to restrict network access to created storage accounts")
bv(&kola.AzureOptions.TrustedLaunch, "azure-trusted-launch", false, "Enable trusted launch for VMs (default \"false\")")

// do-specific options
sv(&kola.DOOptions.ConfigPath, "do-config-file", "", "DigitalOcean config file (default \"~/"+auth.DOConfigPath+"\")")
Expand Down
3 changes: 3 additions & 0 deletions cmd/ore/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/spf13/cobra"

"github.com/flatcar/mantle/cli"
"github.com/flatcar/mantle/platform"
"github.com/flatcar/mantle/platform/api/azure"
)

Expand All @@ -42,10 +43,12 @@ func init() {
}

func preauth(cmd *cobra.Command, args []string) error {
cli.StartLogging(cmd)
plog.Printf("Creating Azure API...")

a, err := azure.New(&azure.Options{
Location: azureLocation,
Options: &platform.Options{},
})
if err != nil {
plog.Fatalf("Failed to create Azure API: %v", err)
Expand Down
118 changes: 118 additions & 0 deletions cmd/ore/azure/create-gallery-image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2018 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package azure

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/flatcar/mantle/platform/api/azure"
"github.com/flatcar/mantle/sdk"
"github.com/spf13/cobra"
)

var (
cmdCreateGalleryImage = &cobra.Command{
Use: "create-gallery-image",
Short: "Create Azure Gallery Image",
Long: "Create Azure Gallery Image mage from a VHD image",
RunE: runCreateGalleryImage,
}

vhd string
blobName string
storageAccount string
resourceGrp string
hyperVGeneration string
board string
)

func init() {
sv := cmdCreateGalleryImage.Flags().StringVar

sv(&imageName, "image-name", "", "image name (optional)")
sv(&blobName, "blob-name", "", "source blob name (optional)")
sv(&vhd, "file", defaultUploadFile(), "source VHD file")
sv(&resourceGrp, "resource-group", "", "resource group name (optional)")
sv(&hyperVGeneration, "hyper-v-generation", "V2", "Hyper-V generation (V2 or V1)")
sv(&board, "board", "amd64-usr", "board name (amd64-usr or arm64-usr)")
sv(&storageAccount, "storage-account", "", "storage account name (optional)")

Azure.AddCommand(cmdCreateGalleryImage)
}

func azureSanitize(name string) string {
name = strings.Replace(name, ".", "-", -1)
name = strings.Replace(name, "+", "-", -1)
return name
}

func runCreateGalleryImage(cmd *cobra.Command, args []string) error {
var err error
if err = api.SetupClients(); err != nil {
plog.Fatalf("setting up clients: %v\n", err)
}
api.Opts.Board = board
api.Opts.HyperVGeneration = hyperVGeneration

if blobName == "" {
ver, err := sdk.VersionsFromDir(filepath.Dir(vhd))
if err != nil {
plog.Fatalf("Unable to get version from image directory, provide a -blob-name flag or include a version.txt in the image directory: %v\n", err)
}
blobName = fmt.Sprintf("flatcar-dev-%s-%s", os.Getenv("USER"), ver.Version)
}
if imageName == "" {
imageName = azureSanitize(strings.TrimSuffix(blobName, ".vhd"))
}
if resourceGrp == "" {
resourceGrp, err = api.CreateResourceGroup("kola-cluster-image")
if err != nil {
plog.Fatalf("Couldn't create resource group: %v\n", err)
}
}
if storageAccount == "" {
storageAccount, err = api.CreateStorageAccount(resourceGrp)
if err != nil {
plog.Fatalf("Couldn't create storage account: %v\n", err)
}
}
client, err := api.GetBlobServiceClient(storageAccount)
if err != nil {
plog.Fatalf("failed to create blob service client for %q: %v", ubo.storageacct, err)
}

container := "vhds"
if err := azure.UploadBlob(client, vhd, container, blobName, true); err != nil {
plog.Fatalf("Uploading blob failed: %v", err)
}
blobUrl := azure.BlobURL(client, container, blobName)
imgID, err := api.CreateGalleryImage(imageName, resourceGrp, storageAccount, blobUrl)
if err != nil {
plog.Fatalf("Couldn't create gallery image: %v\n", err)
}
err = json.NewEncoder(os.Stdout).Encode(&struct {
ID *string
}{
ID: &imgID,
})
if err != nil {
plog.Fatalf("Couldn't encode result: %v\n", err)
}
return nil
}
4 changes: 2 additions & 2 deletions cmd/ore/azure/upload-blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func init() {

func defaultUploadFile() string {
build := sdk.BuildRoot()
return build + "/images/amd64-usr/latest/coreos_production_azure_image.vhd"
return build + "/images/amd64-usr/latest/flatcar_production_azure_image.vhd"
}

func runUploadBlob(cmd *cobra.Command, args []string) {
Expand All @@ -73,7 +73,7 @@ func runUploadBlob(cmd *cobra.Command, args []string) {
if err != nil {
plog.Fatalf("Unable to get version from image directory, provide a -blob-name flag or include a version.txt in the image directory: %v\n", err)
}
ubo.blob = fmt.Sprintf("Container-Linux-dev-%s-%s.vhd", os.Getenv("USER"), ver.Version)
ubo.blob = fmt.Sprintf("flatcar-dev-%s-%s.vhd", os.Getenv("USER"), ver.Version)
}

if err := api.SetupClients(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kola/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func RunTests(patterns []string, channel, offering, pltfrm, outputDir string, ss

version, err := getClusterSemver(flight, outputDir)
if err != nil {
plog.Fatal(err)
return fmt.Errorf("getClusterSemver: %w ", err)
}

// If the version is > 3033, we can safely use user-data instead of custom-data for
Expand All @@ -453,7 +453,7 @@ func RunTests(patterns []string, channel, offering, pltfrm, outputDir string, ss
// one more filter pass now that we know real version
tests, err = FilterTests(tests, patterns, channel, offering, pltfrm, *version)
if err != nil {
plog.Fatal(err)
return fmt.Errorf("FilterTests: %v", err)
}
}

Expand Down
14 changes: 11 additions & 3 deletions kola/tests/misc/nvidia.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package misc
import (
"bytes"
"fmt"
"strings"
"time"

"github.com/coreos/go-semver/semver"
"github.com/coreos/pkg/capnslog"
"github.com/flatcar/mantle/kola"
"github.com/flatcar/mantle/kola/cluster"
Expand All @@ -28,13 +30,19 @@ func init() {
Platforms: []string{"azure"},
Architectures: []string{"amd64"},
Flags: []register.Flag{register.NoEnableSelinux},
SkipFunc: skipOnNonGpu,
})
}

func verifyNvidiaInstallation(c cluster.TestCluster) {
if kola.AzureOptions.Size != "Standard_NC6s_v3" {
c.Skip("skipping due to wrong instance size")
func skipOnNonGpu(version semver.Version, channel, arch, platform string) bool {
// N stands for GPU instance obviously :)
if platform == "azure" && strings.Contains(kola.AzureOptions.Size, "N") {
return false
}
return true
}

func verifyNvidiaInstallation(c cluster.TestCluster) {
m := c.Machines()[0]

nvidiaStatusRetry := func() error {
Expand Down
10 changes: 9 additions & 1 deletion platform/api/azure/gallery-image-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@
{
"name": "DiskControllerTypes",
"value": "NVMe,SCSI"
}
},
{
"name": "SecurityType",
"value": "[if(equals(parameters('hyperVGeneration'), 'V2'), 'TrustedLaunchSupported', 'None')]"
},
{
"name": "IsAcceleratedNetworkSupported",
"value": "true"
}
]
},
"type": "Microsoft.Compute/galleries/images"
Expand Down
4 changes: 2 additions & 2 deletions platform/api/azure/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func (a *API) resolveImage() error {
if a.Opts.DiskURI != "" || a.Opts.BlobURL != "" || a.Opts.ImageFile != "" || a.Opts.Version != "" || a.Opts.Sku == "" {
return nil
}

resp, err := http.DefaultClient.Get(fmt.Sprintf("https://%s.release.flatcar-linux.net/amd64-usr/current/version.txt", a.Opts.Sku))
sku := strings.TrimSuffix(a.Opts.Sku, "-gen2")
resp, err := http.DefaultClient.Get(fmt.Sprintf("https://%s.release.flatcar-linux.net/amd64-usr/current/version.txt", sku))
if err != nil {
return fmt.Errorf("unable to fetch release bucket %v version: %v", a.Opts.Sku, err)
}
Expand Down
Loading