This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
platform/azure: add kola/ore commands for Azure #771
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b59ed2e
vendor: bump azure version & pull in additional libraries
arithx 89b9e96
auth/azure: move ASM options into auth/azure
arithx 05bee9c
platform: move GenerateFakeKey to platform/util
arithx 8f5b8ee
platform/machine/azure: add azure cluster
arithx c084b9c
platform/api/azure: add kola related Azure APIs
arithx d282473
cmd/ore/azure: add ARM based image creation/upload & GC
arithx a3a1a2e
cmd/kola: add Azure
arithx a2fde9c
kola/tests: disable tests on Azure
arithx b0162fb
kola/tests/locksmith/locksmith: update coreos.locksmith.tls
arithx 499ed4a
cmd/plume: update Azure to build API options
arithx f9bd137
README: add Azure configuration docs
arithx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,39 @@ import ( | |
"bytes" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tiny nit: s/form/from/ in commit message. |
||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
|
||
"github.com/coreos/mantle/platform/api/azure" | ||
"golang.org/x/text/encoding/unicode" | ||
"golang.org/x/text/transform" | ||
|
||
"github.com/coreos/mantle/platform" | ||
) | ||
|
||
const ( | ||
AzureAuthPath = ".azure/credentials.json" | ||
AzureProfilePath = ".azure/azureProfile.json" | ||
) | ||
|
||
const AzureProfilePath = ".azure/azureProfile.json" | ||
// A version of the Options struct from platform/api/azure that only | ||
// contains the ASM values. Otherwise there's a cyclical depdendence | ||
// because platform/api/azure has to import auth to have access to | ||
// the ReadAzureProfile function. | ||
type Options struct { | ||
ajeddeloh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*platform.Options | ||
|
||
SubscriptionName string | ||
SubscriptionID string | ||
|
||
// Azure API endpoint. If unset, the Azure SDK default will be used. | ||
ManagementURL string | ||
ManagementCertificate []byte | ||
|
||
// Azure Storage API endpoint suffix. If unset, the Azure SDK default will be used. | ||
StorageEndpointSuffix string | ||
} | ||
|
||
type AzureEnvironment struct { | ||
ActiveDirectoryEndpointURL string `json:"activeDirectoryEndpointUrl"` | ||
|
@@ -68,13 +93,13 @@ type AzureProfile struct { | |
Subscriptions []AzureSubscription `json:"subscriptions"` | ||
} | ||
|
||
// AsOptions converts all subscriptions into a slice of azure.Options. | ||
// AsOptions converts all subscriptions into a slice of Options. | ||
// If there is an environment with a name matching the subscription, that environment's storage endpoint will be copied to the options. | ||
func (ap *AzureProfile) AsOptions() []azure.Options { | ||
var o []azure.Options | ||
func (ap *AzureProfile) AsOptions() []Options { | ||
var o []Options | ||
|
||
for _, sub := range ap.Subscriptions { | ||
newo := azure.Options{ | ||
newo := Options{ | ||
SubscriptionName: sub.Name, | ||
SubscriptionID: sub.ID, | ||
ManagementURL: sub.ManagementEndpointURL, | ||
|
@@ -95,10 +120,10 @@ func (ap *AzureProfile) AsOptions() []azure.Options { | |
return o | ||
} | ||
|
||
// SubscriptionOptions returns the name subscription in the Azure profile as a azure.Options struct. | ||
// SubscriptionOptions returns the name subscription in the Azure profile as a Options struct. | ||
// If the subscription name is "", the first subscription is returned. | ||
// If there are no subscriptions or the named subscription is not found, SubscriptionOptions returns nil. | ||
func (ap *AzureProfile) SubscriptionOptions(name string) *azure.Options { | ||
func (ap *AzureProfile) SubscriptionOptions(name string) *Options { | ||
opts := ap.AsOptions() | ||
|
||
if len(opts) == 0 { | ||
|
@@ -131,14 +156,13 @@ func ReadAzureProfile(path string) (*AzureProfile, error) { | |
path = filepath.Join(user.HomeDir, AzureProfilePath) | ||
} | ||
|
||
f, err := os.Open(path) | ||
contents, err := DecodeBOMFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
var ap AzureProfile | ||
if err := json.NewDecoder(f).Decode(&ap); err != nil { | ||
if err := json.Unmarshal(contents, &ap); err != nil { | ||
return nil, err | ||
} | ||
|
||
|
@@ -148,3 +172,14 @@ func ReadAzureProfile(path string) (*AzureProfile, error) { | |
|
||
return &ap, nil | ||
} | ||
|
||
func DecodeBOMFile(path string) ([]byte, error) { | ||
f, err := os.Open(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
decoder := unicode.UTF8.NewDecoder() | ||
reader := transform.NewReader(f, unicode.BOMOverride(decoder)) | ||
return ioutil.ReadAll(reader) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// 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" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdCreateImageARM = &cobra.Command{ | ||
Use: "create-image-arm", | ||
Short: "Create Azure image", | ||
Long: "Create Azure image from a blob url", | ||
RunE: runCreateImageARM, | ||
} | ||
|
||
imageName string | ||
blobUrl string | ||
resourceGroup string | ||
) | ||
|
||
func init() { | ||
sv := cmdCreateImageARM.Flags().StringVar | ||
|
||
sv(&imageName, "image-name", "", "image name") | ||
sv(&blobUrl, "image-blob", "", "source blob url") | ||
sv(&resourceGroup, "resource-group", "kola", "resource group name") | ||
|
||
Azure.AddCommand(cmdCreateImageARM) | ||
} | ||
|
||
func runCreateImageARM(cmd *cobra.Command, args []string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was really confused for a sec and thought Azure supported ARM. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah ARM (Azure Resource Manager) can be a confusing name when looking from our usual scope. |
||
if err := api.SetupClients(); err != nil { | ||
fmt.Fprintf(os.Stderr, "setting up clients: %v\n", err) | ||
os.Exit(1) | ||
} | ||
img, err := api.CreateImage(imageName, resourceGroup, blobUrl) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Couldn't create image: %v\n", err) | ||
os.Exit(1) | ||
} | ||
if img.ID == nil { | ||
fmt.Fprintf(os.Stderr, "received nil image\n") | ||
os.Exit(1) | ||
} | ||
err = json.NewEncoder(os.Stdout).Encode(&struct { | ||
ID *string | ||
Location *string | ||
}{ | ||
ID: img.ID, | ||
Location: img.Location, | ||
}) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Couldn't encode result: %v\n", err) | ||
os.Exit(1) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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 ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
cmdGC = &cobra.Command{ | ||
Use: "gc", | ||
Short: "GC resources in Azure", | ||
Long: `Delete instances created over the given duration ago`, | ||
RunE: runGC, | ||
} | ||
|
||
gcDuration time.Duration | ||
) | ||
|
||
func init() { | ||
Azure.AddCommand(cmdGC) | ||
cmdGC.Flags().DurationVar(&gcDuration, "duration", 5*time.Hour, "how old resources must be before they're considered garbage") | ||
} | ||
|
||
func runGC(cmd *cobra.Command, args []string) error { | ||
if err := api.SetupClients(); err != nil { | ||
fmt.Fprintf(os.Stderr, "setting up clients: %v\n", err) | ||
os.Exit(1) | ||
} | ||
err := api.GC(gcDuration) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Couldn't gc: %v\n", err) | ||
os.Exit(1) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should note this is from the
az ad sp create-for-rbac