Skip to content

Commit

Permalink
Merge branch 'master' into issue#858
Browse files Browse the repository at this point in the history
  • Loading branch information
buhongw7583c authored Apr 10, 2020
2 parents 4a89de5 + 2c99f3d commit b7bbc9f
Show file tree
Hide file tree
Showing 30 changed files with 1,539 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ test-existing-managers: generate fmt vet manifests
./pkg/resourcemanager/psql/firewallrule/... \
./pkg/resourcemanager/appinsights/... \
./pkg/resourcemanager/vnet/... \
./pkg/resourcemanager/pip/... \
./pkg/resourcemanager/nic/... \
./pkg/resourcemanager/apim/apimgmt... \
./pkg/secrets/...

Expand Down
7 changes: 7 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ resources:
- group: azure
version: v1alpha1
kind: VirtualNetwork
- group: azure
version: v1alpha1
kind: AzurePublicIPAddress
- group: azure
version: v1alpha1
kind: AzureNetworkInterface
- group: azure
version: v1alpha1
kind: AppInsights
Expand All @@ -80,3 +86,4 @@ resources:
- group: azure
version: v1alpha1
kind: MySQLFirewallRule

47 changes: 47 additions & 0 deletions api/v1alpha1/azurenetworkinterface_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.

// AzureNetworkInterfaceSpec defines the desired state of AzureNetworkInterface
type AzureNetworkInterfaceSpec 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"`
VNetName string `json:"vnetName"`
SubnetName string `json:"subnetName"`
PublicIPAddressName string `json:"publicIPAddressName"`
}

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

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

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

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&AzureNetworkInterface{}, &AzureNetworkInterfaceList{})
}
71 changes: 71 additions & 0 deletions api/v1alpha1/azurenetworkinterface_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// 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("AzureNetworkInterface", func() {
var (
key types.NamespacedName
created, fetched *AzureNetworkInterface
)

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 = &AzureNetworkInterface{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
},
Spec: AzureNetworkInterfaceSpec{
Location: "westus",
ResourceGroup: "foo-nic",
VNetName: "test",
SubnetName: "test",
PublicIPAddressName: "test",
}}

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

fetched = &AzureNetworkInterface{}
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())
})

})

})
48 changes: 48 additions & 0 deletions api/v1alpha1/azurepublicipaddress_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.

// AzurePublicIPAddressSpec defines the desired state of AzurePublicIPAddress
type AzurePublicIPAddressSpec 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"`
PublicIPAllocationMethod string `json:"publicIPAllocationMethod"`
IdleTimeoutInMinutes int `json:"idleTimeoutInMinutes"`
PublicIPAddressVersion string `json:"publicIPAddressVersion"`
SkuName string `json:"skuName"`
}

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

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

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

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&AzurePublicIPAddress{}, &AzurePublicIPAddressList{})
}
72 changes: 72 additions & 0 deletions api/v1alpha1/azurepublicipaddress_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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("AzurePublicIPAddress", func() {
var (
key types.NamespacedName
created, fetched *AzurePublicIPAddress
)

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 = &AzurePublicIPAddress{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "default",
},
Spec: AzurePublicIPAddressSpec{
Location: "westus",
ResourceGroup: "foo-pip",
PublicIPAllocationMethod: "Static",
IdleTimeoutInMinutes: 3,
PublicIPAddressVersion: "IPv4",
SkuName: "Basic",
}}

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

fetched = &AzurePublicIPAddress{}
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())
})

})

})
6 changes: 6 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ resources:
- bases/azure.microsoft.com_mysqlservers.yaml
- bases/azure.microsoft.com_mysqldatabases.yaml
- bases/azure.microsoft.com_mysqlfirewallrules.yaml
- bases/azure.microsoft.com_azurepublicipaddresses.yaml
- bases/azure.microsoft.com_azurenetworkinterfaces.yaml
# +kubebuilder:scaffold:crdkustomizeresource

#patches:
Expand Down Expand Up @@ -60,6 +62,8 @@ resources:
#- patches/webhook_in_mysqlservers.yaml
#- patches/webhook_in_mysqldatabases.yaml
#- patches/webhook_in_mysqlfirewallrules.yaml
#- patches/webhook_in_azurepublicipaddresses.yaml
#- patches/webhook_in_azurenetworkinterfaces.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CAINJECTION] patches here are for enabling the CA injection for each CRD
Expand Down Expand Up @@ -88,6 +92,8 @@ resources:
#- patches/cainjection_in_mysqlservers.yaml
#- patches/cainjection_in_mysqldatabases.yaml
#- patches/cainjection_in_mysqlfirewallrules.yaml
#- patches/cainjection_in_azurepublicipaddresses.yaml
#- patches/cainjection_in_azurenetworkinterfaces.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_azurenetworkinterfaces.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: azurenetworkinterfaces.azure.microsoft.com
8 changes: 8 additions & 0 deletions config/crd/patches/cainjection_in_azurepublicipaddresses.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: azurepublicipaddresses.azure.microsoft.com
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_azurenetworkinterfaces.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: azurenetworkinterfaces.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
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_azurepublicipaddresses.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: azurepublicipaddresses.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
10 changes: 10 additions & 0 deletions config/samples/azure_v1alpha1_azurenetworkinterface.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: azure.microsoft.com/v1alpha1
kind: AzureNetworkInterface
metadata:
name: azurenetworkinterface-sample18
spec:
location: westus
resourceGroup: resourcegroup-azure-operators
vnetName: vnet-sample-hpf-1
subnetName: test2
publicIPAddressName: azurepublicipaddress-sample-7
11 changes: 11 additions & 0 deletions config/samples/azure_v1alpha1_azurepublicipaddress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: azure.microsoft.com/v1alpha1
kind: AzurePublicIPAddress
metadata:
name: azurepublicipaddress-sample11
spec:
location: westus
resourceGroup: resourcegroup-azure-operators
publicIPAllocationMethod: "Static"
idleTimeoutInMinutes: 10
publicIPAddressVersion: "IPv4"
skuName: "Basic"
Loading

0 comments on commit b7bbc9f

Please sign in to comment.