armhelpers

package
v0.0.0-...-8a57f99 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2018 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AADContributorRoleID is the role id that exists in every subscription for 'Contributor'
	AADContributorRoleID = "b24988ac-6180-42a0-ab88-20f7382dd24c"
	// AADRoleReferenceTemplate is a template for a roleDefinitionId
	AADRoleReferenceTemplate = "/subscriptions/%s/providers/Microsoft.Authorization/roleDefinitions/%s"
	// AADRoleResourceGroupScopeTemplate is a template for a roleDefinition scope
	AADRoleResourceGroupScopeTemplate = "/subscriptions/%s/resourceGroups/%s"
)
View Source
const (
	// ApplicationDir is the name of the dir where the token is cached
	ApplicationDir = ".acsengine"
)

Variables

View Source
var (
	// RequiredResourceProviders is the list of Azure Resource Providers needed for ACS-Engine to function
	RequiredResourceProviders = []string{"Microsoft.Compute", "Microsoft.Storage", "Microsoft.Network"}
)

Functions

func DeployTemplateSync

func DeployTemplateSync(az ACSEngineClient, logger *logrus.Entry, resourceGroupName, deploymentName string, template map[string]interface{}, parameters map[string]interface{}) error

DeployTemplateSync deploys the template and returns ArmError

Types

type ACSEngineClient

type ACSEngineClient interface {

	//AddAcceptLanguages sets the list of languages to accept on this request
	AddAcceptLanguages(languages []string)

	// DeployTemplate can deploy a template into Azure ARM
	DeployTemplate(resourceGroup, name string, template, parameters map[string]interface{}, cancel <-chan struct{}) (*resources.DeploymentExtended, error)

	// EnsureResourceGroup ensures the specified resource group exists in the specified location
	EnsureResourceGroup(resourceGroup, location string, managedBy *string) (*resources.Group, error)

	// List lists VM resources
	ListVirtualMachines(resourceGroup string) (compute.VirtualMachineListResult, error)

	// GetVirtualMachine retrieves the specified virtual machine.
	GetVirtualMachine(resourceGroup, name string) (compute.VirtualMachine, error)

	// DeleteVirtualMachine deletes the specified virtual machine.
	DeleteVirtualMachine(resourceGroup, name string, cancel <-chan struct{}) (<-chan compute.OperationStatusResponse, <-chan error)

	// ListVirtualMachineScaleSets lists the vmss resources in the resource group
	ListVirtualMachineScaleSets(resourceGroup string) (compute.VirtualMachineScaleSetListResult, error)

	// GetStorageClient uses SRP to retrieve keys, and then an authenticated client for talking to the specified storage
	// account.
	GetStorageClient(resourceGroup, accountName string) (ACSStorageClient, error)

	// DeleteNetworkInterface deletes the specified network interface.
	DeleteNetworkInterface(resourceGroup, nicName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error)

	// CreateGraphAppliction creates an application via the graphrbac client
	CreateGraphApplication(applicationCreateParameters graphrbac.ApplicationCreateParameters) (graphrbac.Application, error)

	// CreateGraphPrincipal creates a service principal via the graphrbac client
	CreateGraphPrincipal(servicePrincipalCreateParameters graphrbac.ServicePrincipalCreateParameters) (graphrbac.ServicePrincipal, error)
	CreateApp(applicationName, applicationURL string) (applicationID, servicePrincipalObjectID, secret string, err error)

	// RBAC
	CreateRoleAssignment(scope string, roleAssignmentName string, parameters authorization.RoleAssignmentCreateParameters) (authorization.RoleAssignment, error)
	CreateRoleAssignmentSimple(applicationID, roleID string) error

	// MANAGED DISKS
	DeleteManagedDisk(resourceGroupName string, diskName string, cancel <-chan struct{}) (<-chan disk.OperationStatusResponse, <-chan error)
	ListManagedDisksByResourceGroup(resourceGroupName string) (result disk.ListType, err error)

	GetKubernetesClient(masterURL, kubeConfig string, interval, timeout time.Duration) (KubernetesClient, error)

	ListProviders() (resources.ProviderListResult, error)

	// ListDeploymentOperations gets all deployments operations for a deployment.
	ListDeploymentOperations(resourceGroupName string, deploymentName string, top *int32) (result resources.DeploymentOperationsListResult, err error)

	// ListDeploymentOperationsNextResults retrieves the next set of results, if any.
	ListDeploymentOperationsNextResults(lastResults resources.DeploymentOperationsListResult) (result resources.DeploymentOperationsListResult, err error)
}

ACSEngineClient is the interface used to talk to an Azure environment. This interface exposes just the subset of Azure APIs and clients needed for ACS-Engine.

type ACSStorageClient

type ACSStorageClient interface {
	// DeleteBlob deletes the specified blob in the specified container.
	DeleteBlob(container, blob string) error
}

ACSStorageClient interface models the azure storage client

type AzureClient

type AzureClient struct {
	// contains filtered or unexported fields
}

AzureClient implements the `ACSEngineClient` interface. This client is backed by real Azure clients talking to an ARM endpoint.

func NewAzureClientWithClientCertificate

func NewAzureClientWithClientCertificate(env azure.Environment, subscriptionID, clientID string, certificate *x509.Certificate, privateKey *rsa.PrivateKey) (*AzureClient, error)

NewAzureClientWithClientCertificate returns an AzureClient via client_id and jwt certificate assertion

func NewAzureClientWithClientCertificateFile

func NewAzureClientWithClientCertificateFile(env azure.Environment, subscriptionID, clientID, certificatePath, privateKeyPath string) (*AzureClient, error)

NewAzureClientWithClientCertificateFile returns an AzureClient via client_id and jwt certificate assertion

func NewAzureClientWithClientSecret

func NewAzureClientWithClientSecret(env azure.Environment, subscriptionID, clientID, clientSecret string) (*AzureClient, error)

NewAzureClientWithClientSecret returns an AzureClient via client_id and client_secret

func NewAzureClientWithDeviceAuth

func NewAzureClientWithDeviceAuth(env azure.Environment, subscriptionID string) (*AzureClient, error)

NewAzureClientWithDeviceAuth returns an AzureClient by having a user complete a device authentication flow

func (*AzureClient) AddAcceptLanguages

func (az *AzureClient) AddAcceptLanguages(languages []string)

AddAcceptLanguages sets the list of languages to accept on this request

func (*AzureClient) CheckDeploymentExistence

func (az *AzureClient) CheckDeploymentExistence(resourceGroupName string, deploymentName string) (result autorest.Response, err error)

CheckDeploymentExistence returns if the deployment already exists

func (*AzureClient) CheckResourceGroupExistence

func (az *AzureClient) CheckResourceGroupExistence(name string) (result autorest.Response, err error)

CheckResourceGroupExistence return if the resource group exists

func (*AzureClient) CreateApp

func (az *AzureClient) CreateApp(appName, appURL string) (applicationID, servicePrincipalObjectID, servicePrincipalClientSecret string, err error)

CreateApp is a simpler method for creating an application

func (*AzureClient) CreateGraphApplication

func (az *AzureClient) CreateGraphApplication(applicationCreateParameters graphrbac.ApplicationCreateParameters) (graphrbac.Application, error)

CreateGraphApplication creates an application via the graphrbac client

func (*AzureClient) CreateGraphPrincipal

func (az *AzureClient) CreateGraphPrincipal(servicePrincipalCreateParameters graphrbac.ServicePrincipalCreateParameters) (graphrbac.ServicePrincipal, error)

CreateGraphPrincipal creates a service principal via the graphrbac client

func (*AzureClient) CreateRoleAssignment

func (az *AzureClient) CreateRoleAssignment(scope string, roleAssignmentName string, parameters authorization.RoleAssignmentCreateParameters) (authorization.RoleAssignment, error)

CreateRoleAssignment creates a role assignment via the authorization client

func (*AzureClient) CreateRoleAssignmentSimple

func (az *AzureClient) CreateRoleAssignmentSimple(resourceGroup, servicePrincipalObjectID string) error

CreateRoleAssignmentSimple is a wrapper around RoleAssignmentsClient.Create

func (*AzureClient) DeleteManagedDisk

func (az *AzureClient) DeleteManagedDisk(resourceGroupName string, diskName string, cancel <-chan struct{}) (<-chan disk.OperationStatusResponse, <-chan error)

DeleteManagedDisk deletes a managed disk.

func (*AzureClient) DeleteNetworkInterface

func (az *AzureClient) DeleteNetworkInterface(resourceGroup, nicName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error)

DeleteNetworkInterface deletes the specified network interface.

func (*AzureClient) DeleteResourceGroup

func (az *AzureClient) DeleteResourceGroup(name string, cancel chan struct{}) (<-chan autorest.Response, <-chan error)

DeleteResourceGroup delete the named resource group

func (*AzureClient) DeleteVirtualMachine

func (az *AzureClient) DeleteVirtualMachine(resourceGroup, name string, cancel <-chan struct{}) (<-chan compute.OperationStatusResponse, <-chan error)

DeleteVirtualMachine handles deletion of a CRP/VMAS VM (aka, not a VMSS VM).

func (*AzureClient) DeployTemplate

func (az *AzureClient) DeployTemplate(resourceGroupName, deploymentName string, template map[string]interface{}, parameters map[string]interface{}, cancel <-chan struct{}) (*resources.DeploymentExtended, error)

DeployTemplate implements the TemplateDeployer interface for the AzureClient client

func (*AzureClient) EnsureProvidersRegistered

func (az *AzureClient) EnsureProvidersRegistered(subscriptionID string) error

EnsureProvidersRegistered checks if the AzureClient is registered to required resource providers and, if not, register subscription to providers

func (*AzureClient) EnsureResourceGroup

func (az *AzureClient) EnsureResourceGroup(name, location string, managedBy *string) (resourceGroup *resources.Group, err error)

EnsureResourceGroup ensures the named resouce group exists in the given location.

func (*AzureClient) GetDeployment

func (az *AzureClient) GetDeployment(resourceGroupName, deploymentName string) (result resources.DeploymentExtended, err error)

GetDeployment returns the template deployment

func (*AzureClient) GetKubernetesClient

func (az *AzureClient) GetKubernetesClient(masterURL, kubeConfig string, interval, timeout time.Duration) (KubernetesClient, error)

GetKubernetesClient returns a KubernetesClient hooked up to the api server at the masterURL

func (*AzureClient) GetStorageClient

func (az *AzureClient) GetStorageClient(resourceGroup, accountName string) (ACSStorageClient, error)

GetStorageClient returns an authenticated client for the specified account.

func (*AzureClient) GetVirtualMachine

func (az *AzureClient) GetVirtualMachine(resourceGroup, name string) (compute.VirtualMachine, error)

GetVirtualMachine returns the specified machine in the specified resource group.

func (*AzureClient) ListDeploymentOperations

func (az *AzureClient) ListDeploymentOperations(resourceGroupName string, deploymentName string, top *int32) (result resources.DeploymentOperationsListResult, err error)

ListDeploymentOperations gets all deployments operations for a deployment.

func (*AzureClient) ListDeploymentOperationsNextResults

func (az *AzureClient) ListDeploymentOperationsNextResults(lastResults resources.DeploymentOperationsListResult) (result resources.DeploymentOperationsListResult, err error)

ListDeploymentOperationsNextResults retrieves the next set of results, if any.

func (*AzureClient) ListManagedDisksByResourceGroup

func (az *AzureClient) ListManagedDisksByResourceGroup(resourceGroupName string) (result disk.ListType, err error)

ListManagedDisksByResourceGroup lists managed disks in a resource group.

func (*AzureClient) ListProviders

func (az *AzureClient) ListProviders() (resources.ProviderListResult, error)

ListProviders returns all the providers for a given AzureClient

func (*AzureClient) ListVirtualMachineScaleSets

func (az *AzureClient) ListVirtualMachineScaleSets(resourceGroup string) (compute.VirtualMachineScaleSetListResult, error)

ListVirtualMachineScaleSets returns (the first page of) the vmss resources in the specified resource group.

func (*AzureClient) ListVirtualMachines

func (az *AzureClient) ListVirtualMachines(resourceGroup string) (compute.VirtualMachineListResult, error)

ListVirtualMachines returns (the first page of) the machines in the specified resource group.

func (*AzureClient) ValidateTemplate

func (az *AzureClient) ValidateTemplate(
	resourceGroupName string,
	deploymentName string,
	template map[string]interface{},
	parameters map[string]interface{}) (result resources.DeploymentValidateResult, err error)

ValidateTemplate validate the template and parameters

type AzureStorageClient

type AzureStorageClient struct {
	// contains filtered or unexported fields
}

AzureStorageClient implements the StorageClient interface and wraps the Azure storage client.

func (*AzureStorageClient) DeleteBlob

func (as *AzureStorageClient) DeleteBlob(vhdContainer, vhdBlob string) error

DeleteBlob deletes the specified blob TODO(colemick): why doesn't SDK give a way to just delete a blob by URI? it's what it ends up doing internally anyway...

type DeploymentError

type DeploymentError struct {
	TopError          error
	StatusCode        int
	Response          []byte
	ProvisioningState string
	OperationsLists   []resources.DeploymentOperationsListResult
}

DeploymentError contains the root deployment error along with deployment operation errors

func (*DeploymentError) Error

func (e *DeploymentError) Error() string

Error implements error interface

type DeploymentValidationError

type DeploymentValidationError struct {
	Err error
}

DeploymentValidationError contains validation error

func (*DeploymentValidationError) Error

func (e *DeploymentValidationError) Error() string

Error implements error interface

type KubernetesClient

type KubernetesClient interface {
	//ListPods returns all Pods running on the passed in node
	ListPods(node *v1.Node) (*v1.PodList, error)
	//GetNode returns details about node with passed in name
	GetNode(name string) (*v1.Node, error)
	//UpdateNode updates the node in the api server with the passed in info
	UpdateNode(node *v1.Node) (*v1.Node, error)
	//SupportEviction queries the api server to discover if it supports eviction, and returns supported type if it is supported
	SupportEviction() (string, error)
	//DeletePod deletes the passed in pod
	DeletePod(pod *v1.Pod) error
	//EvictPod evicts the passed in pod using the passed in api version
	EvictPod(pod *v1.Pod, policyGroupVersion string) error
	//WaitForDelete waits until all pods are deleted. Returns all pods not deleted and an error on failure
	WaitForDelete(logger *log.Entry, pods []v1.Pod, usingEviction bool) ([]v1.Pod, error)
}

KubernetesClient interface models client for interacting with kubernetes api server

type KubernetesClientSetClient

type KubernetesClientSetClient struct {
	// contains filtered or unexported fields
}

KubernetesClientSetClient kubernetes client hooked up to a live api server

func (*KubernetesClientSetClient) DeletePod

func (c *KubernetesClientSetClient) DeletePod(pod *v1.Pod) error

DeletePod deletes the passed in pod

func (*KubernetesClientSetClient) EvictPod

func (c *KubernetesClientSetClient) EvictPod(pod *v1.Pod, policyGroupVersion string) error

EvictPod evicts the passed in pod using the passed in api version

func (*KubernetesClientSetClient) GetNode

func (c *KubernetesClientSetClient) GetNode(name string) (*v1.Node, error)

GetNode returns details about node with passed in name

func (*KubernetesClientSetClient) ListPods

func (c *KubernetesClientSetClient) ListPods(node *v1.Node) (*v1.PodList, error)

ListPods returns all Pods running on the passed in node

func (*KubernetesClientSetClient) SupportEviction

func (c *KubernetesClientSetClient) SupportEviction() (string, error)

SupportEviction queries the api server to discover if it supports eviction, and returns supported type if it is supported

func (*KubernetesClientSetClient) UpdateNode

func (c *KubernetesClientSetClient) UpdateNode(node *v1.Node) (*v1.Node, error)

UpdateNode updates the node in the api server with the passed in info

func (*KubernetesClientSetClient) WaitForDelete

func (c *KubernetesClientSetClient) WaitForDelete(logger *log.Entry, pods []v1.Pod, usingEviction bool) ([]v1.Pod, error)

WaitForDelete waits until all pods are deleted. Returns all pods not deleted and an error on failure

type MockACSEngineClient

type MockACSEngineClient struct {
	FailDeployTemplate              bool
	FailDeployTemplateQuota         bool
	FailDeployTemplateConflict      bool
	FailEnsureResourceGroup         bool
	FailListVirtualMachines         bool
	FailListVirtualMachineScaleSets bool
	FailGetVirtualMachine           bool
	FailDeleteVirtualMachine        bool
	FailGetStorageClient            bool
	FailDeleteNetworkInterface      bool
	FailGetKubernetesClient         bool
	FailListProviders               bool
	MockKubernetesClient            *MockKubernetesClient
}

MockACSEngineClient is an implementation of ACSEngineClient where all requests error out

func (*MockACSEngineClient) AddAcceptLanguages

func (mc *MockACSEngineClient) AddAcceptLanguages(languages []string)

AddAcceptLanguages mock

func (*MockACSEngineClient) CreateApp

func (mc *MockACSEngineClient) CreateApp(applicationName, applicationURL string) (applicationID, servicePrincipalObjectID, secret string, err error)

CreateApp is a simpler method for creating an application

func (*MockACSEngineClient) CreateGraphApplication

func (mc *MockACSEngineClient) CreateGraphApplication(applicationCreateParameters graphrbac.ApplicationCreateParameters) (graphrbac.Application, error)

CreateGraphApplication creates an application via the graphrbac client

func (*MockACSEngineClient) CreateGraphPrincipal

func (mc *MockACSEngineClient) CreateGraphPrincipal(servicePrincipalCreateParameters graphrbac.ServicePrincipalCreateParameters) (graphrbac.ServicePrincipal, error)

CreateGraphPrincipal creates a service principal via the graphrbac client

func (*MockACSEngineClient) CreateRoleAssignment

func (mc *MockACSEngineClient) CreateRoleAssignment(scope string, roleAssignmentName string, parameters authorization.RoleAssignmentCreateParameters) (authorization.RoleAssignment, error)

CreateRoleAssignment creates a role assignment via the authorization client

func (*MockACSEngineClient) CreateRoleAssignmentSimple

func (mc *MockACSEngineClient) CreateRoleAssignmentSimple(applicationID, roleID string) error

CreateRoleAssignmentSimple is a wrapper around RoleAssignmentsClient.Create

func (*MockACSEngineClient) DeleteManagedDisk

func (mc *MockACSEngineClient) DeleteManagedDisk(resourceGroupName string, diskName string, cancel <-chan struct{}) (<-chan disk.OperationStatusResponse, <-chan error)

DeleteManagedDisk is a wrapper around disksClient.Delete

func (*MockACSEngineClient) DeleteNetworkInterface

func (mc *MockACSEngineClient) DeleteNetworkInterface(resourceGroup, nicName string, cancel <-chan struct{}) (<-chan autorest.Response, <-chan error)

DeleteNetworkInterface mock

func (*MockACSEngineClient) DeleteVirtualMachine

func (mc *MockACSEngineClient) DeleteVirtualMachine(resourceGroup, name string, cancel <-chan struct{}) (<-chan compute.OperationStatusResponse, <-chan error)

DeleteVirtualMachine mock

func (*MockACSEngineClient) DeployTemplate

func (mc *MockACSEngineClient) DeployTemplate(resourceGroup, name string, template, parameters map[string]interface{}, cancel <-chan struct{}) (*resources.DeploymentExtended, error)

DeployTemplate mock

func (*MockACSEngineClient) EnsureResourceGroup

func (mc *MockACSEngineClient) EnsureResourceGroup(resourceGroup, location string, managedBy *string) (*resources.Group, error)

EnsureResourceGroup mock

func (*MockACSEngineClient) GetKubernetesClient

func (mc *MockACSEngineClient) GetKubernetesClient(masterURL, kubeConfig string, interval, timeout time.Duration) (KubernetesClient, error)

GetKubernetesClient mock

func (*MockACSEngineClient) GetStorageClient

func (mc *MockACSEngineClient) GetStorageClient(resourceGroup, accountName string) (ACSStorageClient, error)

GetStorageClient mock

func (*MockACSEngineClient) GetVirtualMachine

func (mc *MockACSEngineClient) GetVirtualMachine(resourceGroup, name string) (compute.VirtualMachine, error)

GetVirtualMachine mock

func (*MockACSEngineClient) ListDeploymentOperations

func (mc *MockACSEngineClient) ListDeploymentOperations(resourceGroupName string, deploymentName string, top *int32) (result resources.DeploymentOperationsListResult, err error)

ListDeploymentOperations gets all deployments operations for a deployment.

func (*MockACSEngineClient) ListDeploymentOperationsNextResults

func (mc *MockACSEngineClient) ListDeploymentOperationsNextResults(lastResults resources.DeploymentOperationsListResult) (result resources.DeploymentOperationsListResult, err error)

ListDeploymentOperationsNextResults retrieves the next set of results, if any.

func (*MockACSEngineClient) ListManagedDisksByResourceGroup

func (mc *MockACSEngineClient) ListManagedDisksByResourceGroup(resourceGroupName string) (result disk.ListType, err error)

ListManagedDisksByResourceGroup is a wrapper around disksClient.ListManagedDisksByResourceGroup

func (*MockACSEngineClient) ListProviders

func (mc *MockACSEngineClient) ListProviders() (resources.ProviderListResult, error)

ListProviders mock

func (*MockACSEngineClient) ListVirtualMachineScaleSets

func (mc *MockACSEngineClient) ListVirtualMachineScaleSets(resourceGroup string) (compute.VirtualMachineScaleSetListResult, error)

ListVirtualMachineScaleSets mock

func (*MockACSEngineClient) ListVirtualMachines

func (mc *MockACSEngineClient) ListVirtualMachines(resourceGroup string) (compute.VirtualMachineListResult, error)

ListVirtualMachines mock

type MockKubernetesClient

type MockKubernetesClient struct {
	FailListPods          bool
	FailGetNode           bool
	UpdateNodeFunc        func(*v1.Node) (*v1.Node, error)
	FailUpdateNode        bool
	FailSupportEviction   bool
	FailDeletePod         bool
	FailEvictPod          bool
	FailWaitForDelete     bool
	ShouldSupportEviction bool
	PodsList              *v1.PodList
}

MockKubernetesClient mock implementation of KubernetesClient

func (*MockKubernetesClient) DeletePod

func (mkc *MockKubernetesClient) DeletePod(pod *v1.Pod) error

DeletePod deletes the passed in pod

func (*MockKubernetesClient) EvictPod

func (mkc *MockKubernetesClient) EvictPod(pod *v1.Pod, policyGroupVersion string) error

EvictPod evicts the passed in pod using the passed in api version

func (*MockKubernetesClient) GetNode

func (mkc *MockKubernetesClient) GetNode(name string) (*v1.Node, error)

GetNode returns details about node with passed in name

func (*MockKubernetesClient) ListPods

func (mkc *MockKubernetesClient) ListPods(node *v1.Node) (*v1.PodList, error)

ListPods returns all Pods running on the passed in node

func (*MockKubernetesClient) SupportEviction

func (mkc *MockKubernetesClient) SupportEviction() (string, error)

SupportEviction queries the api server to discover if it supports eviction, and returns supported type if it is supported

func (*MockKubernetesClient) UpdateNode

func (mkc *MockKubernetesClient) UpdateNode(node *v1.Node) (*v1.Node, error)

UpdateNode updates the node in the api server with the passed in info

func (*MockKubernetesClient) WaitForDelete

func (mkc *MockKubernetesClient) WaitForDelete(logger *log.Entry, pods []v1.Pod, usingEviction bool) ([]v1.Pod, error)

WaitForDelete waits until all pods are deleted. Returns all pods not deleted and an error on failure

type MockStorageClient

type MockStorageClient struct{}

MockStorageClient mock implementation of StorageClient

func (*MockStorageClient) DeleteBlob

func (msc *MockStorageClient) DeleteBlob(container, blob string) error

DeleteBlob mock

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL