Skip to content

Commit

Permalink
Merge branch 'cloud-suffix' of https://github.com/jananivMS/azure-ser…
Browse files Browse the repository at this point in the history
…vice-operator into cloud-suffix
  • Loading branch information
jananivMS committed Apr 21, 2020
2 parents d259e00 + 85c1bb1 commit b98806d
Show file tree
Hide file tree
Showing 68 changed files with 2,277 additions and 434 deletions.
4 changes: 3 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ resources:
- group: azure
version: v1alpha1
kind: MySQLFirewallRule

- group: azure
version: v1alpha1
kind: AzureVirtualMachine
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ This project maintains [releases of the Azure Service Operator](https://github.c
1. [Resource Group](/docs/resourcegroup/resourcegroup.md)
2. [EventHub](/docs/eventhub/eventhub.md)
3. [Azure SQL](/docs/azuresql/azuresql.md)
4. [Azure Keyvault](/docs/keyvault/keyvault.md)
5. [Azure Rediscache](/docs/rediscache/rediscache.md)
6. [Storage Account](/docs/storage/storageaccount.md)
7. [Blob container](/docs/storage/blobcontainer.md)
8. [Azure Database for PostgreSQL](/docs/postgresql/postgresql.md)
9. [Virtual Network](/docs/virtualnetwork/virtualnetwork.md)
10.[Application Insights](/docs/appinsights/appinsights.md)
11.[API Management](/docs/apimgmt/apimgmt.md)
12.[Cosmos DB](/docs/cosmosdb/cosmosdb.md)
4. [Azure Database for PostgreSQL](/docs/postgresql/postgresql.md)
5. [Azure Database for MySQL](/docs/mysql/mysql.md)
6. [Azure Keyvault](/docs/keyvault/keyvault.md)
7. [Azure Rediscache](/docs/rediscache/rediscache.md)
8. [Storage Account](/docs/storage/storageaccount.md)
9. [Blob container](/docs/storage/blobcontainer.md)
10. [Virtual Network](/docs/virtualnetwork/virtualnetwork.md)
11. [Application Insights](/docs/appinsights/appinsights.md)
12. [API Management](/docs/apimgmt/apimgmt.md)
13. [Cosmos DB](/docs/cosmosdb/cosmosdb.md)

For more information on deploying, troubleshooting & deleting resources, refer to [this](/docs/customresource.md) link

Expand Down
59 changes: 59 additions & 0 deletions api/v1alpha1/azurevirtualmachine_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// AzureVirtualMachineSpec defines the desired state of AzureVirtualMachine
type AzureVirtualMachineSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Location string `json:"location"`
ResourceGroup string `json:"resourceGroup"`
VMSize string `json:"vmSize"`
OSType OSType `json:"osType"`
AdminUserName string `json:"adminUserName"`
SSHPublicKeyData string `json:"sshPublicKeyData,omitempty"`
NetworkInterfaceName string `json:"networkInterfaceName"`
PlatformImageURN string `json:"platformImageURN"`
}

type OSType string

const (
// Windows ...
Windows OSType = "Windows"
// Linux ...
Linux OSType = "Linux"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// AzureVirtualMachine is the Schema for the azurevirtualmachines API
type AzureVirtualMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AzureVirtualMachineSpec `json:"spec,omitempty"`
Status ASOStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// AzureVirtualMachineList contains a list of AzureVirtualMachine
type AzureVirtualMachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AzureVirtualMachine `json:"items"`
}

func init() {
SchemeBuilder.Register(&AzureVirtualMachine{}, &AzureVirtualMachineList{})
}
74 changes: 74 additions & 0 deletions api/v1alpha1/azurevirtualmachine_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"golang.org/x/net/context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

// These tests are written in BDD-style using Ginkgo framework. Refer to
// http://onsi.github.io/ginkgo to learn more.

var _ = Describe("AzureVirtualMachine", func() {
var (
key types.NamespacedName
created, fetched *AzureVirtualMachine
)

BeforeEach(func() {
// Add any setup steps that needs to be executed before each test
})

AfterEach(func() {
// Add any teardown steps that needs to be executed after each test
})

// Add Tests for OpenAPI validation (or additonal CRD features) specified in
// your API definition.
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Context("Create API", func() {

It("should create an object successfully", func() {

key = types.NamespacedName{
Name: "foo",
Namespace: "default",
}
created = &AzureVirtualMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
},
Spec: AzureVirtualMachineSpec{
Location: "westus",
ResourceGroup: "foo-vm",
VMSize: "test",
OSType: OSType("Linux"),
AdminUserName: "test",
SSHPublicKeyData: "test",
NetworkInterfaceName: "test",
PlatformImageURN: "w:x:y:z",
}}

By("creating an API obj")
Expect(k8sClient.Create(context.TODO(), created)).To(Succeed())

fetched = &AzureVirtualMachine{}
Expect(k8sClient.Get(context.TODO(), key, fetched)).To(Succeed())
Expect(fetched).To(Equal(created))

By("deleting the created object")
Expect(k8sClient.Delete(context.TODO(), created)).To(Succeed())
Expect(k8sClient.Get(context.TODO(), key, created)).ToNot(Succeed())
})

})

})
25 changes: 19 additions & 6 deletions api/v1alpha1/cosmosdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ type CosmosDBSpec struct {

// +kubebuilder:validation:MinLength=0

Location string `json:"location,omitempty"`
ResourceGroup string `json:"resourceGroup"`
Kind CosmosDBKind `json:"kind,omitempty"`
Properties CosmosDBProperties `json:"properties,omitempty"`
Location string `json:"location,omitempty"`
ResourceGroup string `json:"resourceGroup"`
Kind CosmosDBKind `json:"kind,omitempty"`
Properties CosmosDBProperties `json:"properties,omitempty"`
VirtualNetworkRules *[]CosmosDBVirtualNetworkRule `json:"virtualNetworkRules,omitempty"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
}

// CosmosDBKind enumerates the values for kind.
Expand All @@ -39,9 +41,12 @@ const (

// CosmosDBProperties the CosmosDBProperties of CosmosDB.
type CosmosDBProperties struct {
// CosmosDBDatabaseAccountOfferType - The offer type for the Cosmos DB database account.
// DatabaseAccountOfferType - The offer type for the Cosmos DB database account.
DatabaseAccountOfferType CosmosDBDatabaseAccountOfferType `json:"databaseAccountOfferType,omitempty"`
//Locations []CosmosDBLocation `json:"locations,omitempty"`
// IsVirtualNetworkFilterEnabled - Flag to indicate whether to enable/disable Virtual Network ACL rules.
IsVirtualNetworkFilterEnabled bool `json:"isVirtualNetworkFilterEnabled,omitempty"`
EnableMultipleWriteLocations bool `json:"enableMultipleWriteLocations,omitempty"`
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
}

// +kubebuilder:validation:Enum=Standard
Expand Down Expand Up @@ -82,6 +87,14 @@ type CosmosDBList struct {
Items []CosmosDB `json:"items"`
}

//CosmosDBVirtualNetworkRule virtual Network ACL Rule object
type CosmosDBVirtualNetworkRule struct {
// ID - Resource ID of a subnet, for example: /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}.
SubnetID *string `json:"subnetID,omitempty"`
// IgnoreMissingVNetServiceEndpoint - Create firewall rule before the virtual network has vnet service endpoint enabled.
IgnoreMissingVNetServiceEndpoint *bool `json:"ignoreMissingVNetServiceEndpoint,omitempty"`
}

func init() {
SchemeBuilder.Register(&CosmosDB{}, &CosmosDBList{})
}
Expand Down
30 changes: 27 additions & 3 deletions api/v1alpha1/mysqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type MySQLServerSpec struct {
Sku AzureDBsSQLSku `json:"sku,omitempty"`
ServerVersion ServerVersion `json:"serverVersion,omitempty"`
SSLEnforcement SslEnforcementEnum `json:"sslEnforcement,omitempty"`
CreateMode string `json:"createMode,omitempty"`
ReplicaProperties ReplicaProperties `json:"replicaProperties,omitempty"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
}

Expand All @@ -41,6 +43,10 @@ type MySQLServerList struct {
Items []MySQLServer `json:"items"`
}

type ReplicaProperties struct {
SourceServerId string `json:"sourceServerId,omitempty"`
}

func init() {
SchemeBuilder.Register(&MySQLServer{}, &MySQLServerList{})
}
Expand All @@ -55,14 +61,32 @@ func NewDefaultMySQLServer(name, resourceGroup, location string) *MySQLServer {
Location: location,
ResourceGroup: resourceGroup,
Sku: AzureDBsSQLSku{
Name: "B_Gen5_2",
Tier: SkuTier("Basic"),
Name: "GP_Gen5_4",
Tier: SkuTier("GeneralPurpose"),
Family: "Gen5",
Size: "51200",
Capacity: 2,
Capacity: 4,
},
ServerVersion: ServerVersion("8.0"),
SSLEnforcement: SslEnforcementEnumEnabled,
CreateMode: "Default",
},
}
}

func NewReplicaMySQLServer(name, resourceGroup, location string, sourceserverid string) *MySQLServer {
return &MySQLServer{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: "default",
},
Spec: MySQLServerSpec{
Location: location,
ResourceGroup: resourceGroup,
CreateMode: "Replica",
ReplicaProperties: ReplicaProperties{
SourceServerId: sourceserverid,
},
},
}
}
39 changes: 39 additions & 0 deletions api/v1alpha1/storageaccount_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type StorageAccountSpec struct {
EnableHTTPSTrafficOnly *bool `json:"supportsHttpsTrafficOnly,omitempty"`

DataLakeEnabled *bool `json:"dataLakeEnabled,omitempty"`

NetworkRule *StorageNetworkRuleSet `json:"networkRule,omitempty"`
}

// StorageAccountSku the SKU of the storage account.
Expand Down Expand Up @@ -97,6 +99,43 @@ type StorageAccountList struct {
Items []StorageAccount `json:"items"`
}

type Bypass string

type StorageNetworkRuleSet struct {
// Bypass - Specifies whether traffic is bypassed for Logging/Metrics/AzureServices.
//Possible values are any combination of Logging|Metrics|AzureServices (For example, "Logging, Metrics"), or None to bypass none of those traffics.
//Possible values include: 'None', 'Logging', 'Metrics', 'AzureServices'
Bypass Bypass `json:"bypass,omitempty"`
// VirtualNetworkRules - Sets the virtual network rules
VirtualNetworkRules *[]VirtualNetworkRule `json:"virtualNetworkRules,omitempty"`
// IPRules - Sets the IP ACL rules
IPRules *[]IPRule `json:"ipRules,omitempty"`
// DefaultAction - Specifies the default action of allow or deny when no other rules match. Possible values include: 'DefaultActionAllow', 'DefaultActionDeny'
DefaultAction string `json:"defaultAction,omitempty"`
}

const (

// AzureServices ...
AzureServices Bypass = "AzureServices"
// Logging ...
Logging Bypass = "Logging"
// Metrics ...
Metrics Bypass = "Metrics"
// None ...
None Bypass = "None"
)

type VirtualNetworkRule struct {
// SubnetId - Resource ID of a subnet, for example: /subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}.
SubnetId *string `json:"subnetId,omitempty"`
}

type IPRule struct {
// IPAddressOrRange - Specifies the IP or IP range in CIDR format. Only IPV4 address is allowed.
IPAddressOrRange *string `json:"ipAddressOrRange,omitempty"`
}

func init() {
SchemeBuilder.Register(&StorageAccount{}, &StorageAccountList{})
}
Expand Down
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resources:
- bases/azure.microsoft.com_mysqlfirewallrules.yaml
- bases/azure.microsoft.com_azurepublicipaddresses.yaml
- bases/azure.microsoft.com_azurenetworkinterfaces.yaml
- bases/azure.microsoft.com_azurevirtualmachines.yaml
# +kubebuilder:scaffold:crdkustomizeresource

#patches:
Expand Down Expand Up @@ -65,6 +66,7 @@ resources:
#- patches/webhook_in_storageaccounts.yaml
#- patches/webhook_in_azurepublicipaddresses.yaml
#- patches/webhook_in_azurenetworkinterfaces.yaml
#- patches/webhook_in_azurevirtualmachines.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CAINJECTION] patches here are for enabling the CA injection for each CRD
Expand Down Expand Up @@ -96,6 +98,7 @@ resources:
#- patches/cainjection_in_storageaccounts.yaml
#- patches/cainjection_in_azurepublicipaddresses.yaml
#- patches/cainjection_in_azurenetworkinterfaces.yaml
#- patches/cainjection_in_azurevirtualmachines.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
8 changes: 8 additions & 0 deletions config/crd/patches/cainjection_in_azurevirtualmachines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
certmanager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: azurevirtualmachines.azure.microsoft.com
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_azurevirtualmachines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: azurevirtualmachines.azure.microsoft.com
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
14 changes: 14 additions & 0 deletions config/samples/azure_v1alpha1_azurevirtualmachine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: azure.microsoft.com/v1alpha1
kind: AzureVirtualMachine
metadata:
name: hpfvm20
spec:
location: SouthCentralUS
resourceGroup: resourcegroup-azure-operators
vmSize: Standard_DS1_v2
osType: Linux
adminUserName: azureuser
# SSH public key to be used with VM (eg cat ~/.ssh/id_rsa.pub)
sshPublicKeyData: "{ssh public key}"
networkInterfaceName: hpfnic20
platformImageURN: Canonical:UbuntuServer:16.04-LTS:latest
Loading

0 comments on commit b98806d

Please sign in to comment.