Skip to content

Commit

Permalink
fix: New Compute and Network micro services convering machine, cluste…
Browse files Browse the repository at this point in the history
…r to pure ARM calls (#139)

fix: New Compute and Network micro services convering machine, cluster to pure ARM calls

fix: New Network services which can be used by top level reconciler

Add Virtual Machine and Virtual Machine Extensions as well, unforunately this is a massive PR

Atleast create single node clusters

Add Azure Cloud provider config to all masters and client

Use Internal LB IP for nodes to communicate with Control plane

Move all defaults to a separate file under services

Minor fix to remove any accidental tabs present in yaml file used in startup script

Move AdminKubeconfig and DiscoveryHashes back to ClusterConfig, since kubeadm uses on disk certificates, we only update if the spec certs are empty, causing mismatch

Address review comments, convert spec to an defined interface and use ref rather than value
  • Loading branch information
awesomenix authored and openshift-merge-robot committed Mar 25, 2019
1 parent 803aefe commit a818b2d
Show file tree
Hide file tree
Showing 162 changed files with 22,732 additions and 2,889 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager sigs.k8s.io/clu
FROM alpine:3.9
WORKDIR /root/
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-azure/manager .
COPY --from=builder /go/src/sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/resources/template/deployment-template.json .
ENTRYPOINT ["./manager"]
16 changes: 11 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/clusterctl/examples/azure/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ CREDENTIALS_FILE=${OUTPUT_DIR}/credentials.sh
CLUSTER_TEMPLATE_FILE=${DIR}/cluster.yaml.template
CLUSTER_GENERATED_FILE=${OUTPUT_DIR}/cluster.yaml
# TODO: Change the machine template once nodes are implemented
MACHINES_TEMPLATE_FILE=${DIR}/machines_no_node.yaml.template
MACHINES_TEMPLATE_FILE=${DIR}/machines.yaml.template
MACHINES_GENERATED_FILE=${OUTPUT_DIR}/machines.yaml
MANAGER_PATCH_TEMPLATE_FILE=${DIR}/azure_manager_image_patch.yaml.template
MANAGER_PATCH_GENERATED_FILE=${OUTPUT_DIR}/azure_manager_image_patch.yaml
Expand Down
1 change: 0 additions & 1 deletion cmd/clusterctl/examples/azure/machines.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ items:
spec:
versions:
kubelet: 1.13.4
controlPlane: 1.13.4
providerSpec:
value:
apiVersion: azureprovider/v1alpha1
Expand Down
12 changes: 4 additions & 8 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,16 @@ Here's an example of how to build controller images, if you're interested in tes

```bash
# Build the image.
PREFIX=quay.io/k8s \
NAME=cluster-api-azure-controller \
TAG=0.1.0-alpha.3 \
make docker-build
STABLE_DOCKER_REPO=quay.io/<name here> make docker-build

# Push the image.
PREFIX=quay.io/k8s \
NAME=cluster-api-azure-controller \
TAG=0.1.0-alpha.3 \
make docker-push
STABLE_DOCKER_REPO=quay.io/<name here> make docker-push
```

**NOTE:** In order for the created images to be used for testing, you must push them to a public container registry.

MANAGER_IMAGE must point to right repo, to make sure the image is picked up by bootstrap and target cluster

### Submitting PRs and testing

Pull requests and issues are highly encouraged!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ type AzureClusterProviderSpec struct {
// SAKeyPair is the service account key pair.
SAKeyPair KeyPair `json:"saKeyPair,omitempty"`

// AdminKubeconfig generated using the certificates part of the spec
// do not move to status, since it uses on disk ca certs, which causes issues during regeneration
AdminKubeconfig string `json:"adminKubeconfig,omitempty"`

// DiscoveryHashes generated using the certificates part of the spec, used by master and nodes bootstrapping
// this never changes until ca is rotated
// do not move to status, since it uses on disk ca certs, which causes issues during regeneration
DiscoveryHashes []string `json:"discoveryHashes,omitempty"`

// ClusterConfiguration holds the cluster-wide information used during a
// kubeadm init call.
ClusterConfiguration kubeadmv1beta1.ClusterConfiguration `json:"clusterConfiguration,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ type AzureClusterProviderStatus struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

CertificateStatus CertificateStatus `json:"certificateStatus,omitempty"`
Network Network `json:"network,omitempty"`
Bastion VM `json:"bastion,omitempty"`
Network Network `json:"network,omitempty"`
Bastion VM `json:"bastion,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
10 changes: 0 additions & 10 deletions pkg/apis/azureprovider/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,6 @@ type Network struct {
APIServerIP PublicIP `json:"apiServerIp,omitempty"`
}

//CertificateStatus contains fields generated along with certificate generation
type CertificateStatus struct {
// AdminKubeconfig generated using the certificates part of the spec
AdminKubeconfig string `json:"adminKubeconfig,omitempty"`

// DiscoveryHashes generated using the certificates part of the spec, used by master and nodes bootstrapping
// this never changes until ca is rotated
DiscoveryHashes []string `json:"discoveryHashes,omitempty"`
}

// TODO: Implement tagging
/*
// Tags defines resource tags.
Expand Down
27 changes: 5 additions & 22 deletions pkg/apis/azureprovider/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pkg/cloud/azure/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"defaults.go",
"errors.go",
"fake_interfaces.go",
"interfaces.go",
],
importpath = "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure",
visibility = ["//visibility:public"],
deps = ["//vendor/github.com/Azure/go-autorest/autorest:go_default_library"],
)
4 changes: 1 addition & 3 deletions pkg/cloud/azure/actuators/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/azureprovider/v1alpha1:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network:go_default_library",
"//vendor/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources:go_default_library",
"//pkg/cloud/azure:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest:go_default_library",
"//vendor/github.com/Azure/go-autorest/autorest/azure/auth:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
Expand Down
82 changes: 14 additions & 68 deletions pkg/cloud/azure/actuators/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,26 @@ limitations under the License.
package actuators

import (
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"fmt"
"hash/fnv"
"strings"

"github.com/Azure/go-autorest/autorest"
providerv1 "sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure"
)

// AzureClients contains all the Azure clients used by the scopes.
type AzureClients struct {
SubscriptionID string

Authorizer autorest.Authorizer
// TODO: Remove legacy clients once interfaces are reimplemented
Compute AzureComputeClient
Network AzureNetworkClient
Resources AzureResourcesClient

// Compute
VM compute.VirtualMachinesClient
Disks compute.DisksClient

// Network
VirtualNetworks network.VirtualNetworksClient
SecurityGroups network.SecurityGroupsClient
Interfaces network.InterfacesClient
LB network.LoadBalancersClient
PublicIPAddresses network.PublicIPAddressesClient

// Resources
Deployments resources.DeploymentsClient
Tags resources.TagsClient
}

// AzureComputeClient defines the operations that will interact with the Azure Compute API
type AzureComputeClient interface {
// Virtual Machines Operations
RunCommand(resoureGroup string, name string, cmd string) (compute.VirtualMachinesRunCommandFuture, error)
VMIfExists(resourceGroup string, name string) (*compute.VirtualMachine, error)
DeleteVM(resourceGroup string, name string) (compute.VirtualMachinesDeleteFuture, error)
WaitForVMRunCommandFuture(future compute.VirtualMachinesRunCommandFuture) error
WaitForVMDeletionFuture(future compute.VirtualMachinesDeleteFuture) error

// Disk Operations
DeleteManagedDisk(resourceGroup string, name string) (compute.DisksDeleteFuture, error)
WaitForDisksDeleteFuture(future compute.DisksDeleteFuture) error
}

// AzureNetworkClient defines the operations that will interact with the Azure Network API
type AzureNetworkClient interface {
// Network Interfaces Operations
DeleteNetworkInterface(resourceGroupName string, networkInterfaceName string) (network.InterfacesDeleteFuture, error)
WaitForNetworkInterfacesDeleteFuture(future network.InterfacesDeleteFuture) error

// Network Security Groups Operations
CreateOrUpdateNetworkSecurityGroup(resourceGroupName string, networkSecurityGroupName string, location string) (*network.SecurityGroupsCreateOrUpdateFuture, error)
NetworkSGIfExists(resourceGroupName string, networkSecurityGroupName string) (*network.SecurityGroup, error)
WaitForNetworkSGsCreateOrUpdateFuture(future network.SecurityGroupsCreateOrUpdateFuture) error

// Public Ip Address Operations
CreateOrUpdatePublicIPAddress(resourceGroupName string, IPName string) (network.PublicIPAddress, error)
DeletePublicIPAddress(resourceGroup string, IPName string) (network.PublicIPAddressesDeleteFuture, error)
WaitForPublicIPAddressDeleteFuture(future network.PublicIPAddressesDeleteFuture) error

// Virtual Networks Operations
CreateOrUpdateVnet(resourceGroupName string, virtualNetworkName string, location string) (*network.VirtualNetworksCreateOrUpdateFuture, error)
WaitForVnetCreateOrUpdateFuture(future network.VirtualNetworksCreateOrUpdateFuture) error
Authorizer autorest.Authorizer
}

// AzureResourcesClient defines the operations that will interact with the Azure Resources API
type AzureResourcesClient interface {
// Deployment Operations
CreateOrUpdateDeployment(machine *clusterv1.Machine, clusterConfig *providerv1.AzureClusterProviderSpec, machineConfig *providerv1.AzureMachineProviderSpec, startupScript string) (*resources.DeploymentsCreateOrUpdateFuture, error)
GetDeploymentResult(future resources.DeploymentsCreateOrUpdateFuture) (de resources.DeploymentExtended, err error)
ValidateDeployment(machine *clusterv1.Machine, clusterConfig *providerv1.AzureClusterProviderSpec, machineConfig *providerv1.AzureMachineProviderSpec, startupScript string) error
WaitForDeploymentsCreateOrUpdateFuture(future resources.DeploymentsCreateOrUpdateFuture) error
// CreateOrUpdateNetworkAPIServerIP creates or updates public ip name and dns name
func CreateOrUpdateNetworkAPIServerIP(scope *Scope) {
if scope.Network().APIServerIP.Name == "" {
h := fnv.New32a()
h.Write([]byte(fmt.Sprintf("%s/%s/%s", scope.SubscriptionID, scope.ClusterConfig.ResourceGroup, scope.Cluster.Name)))
scope.Network().APIServerIP.Name = strings.ToLower(azure.DefaultPublicIPPrefix + fmt.Sprintf("%x", h.Sum32()))
}
scope.Network().APIServerIP.DNSName = fmt.Sprintf("%s.%s.%s", strings.ToLower(scope.Network().APIServerIP.Name), strings.ToLower(scope.ClusterConfig.Location), azure.DefaultAzureDNSZone)
}
13 changes: 10 additions & 3 deletions pkg/cloud/azure/actuators/cluster/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ go_library(
importpath = "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/actuators/cluster",
visibility = ["//visibility:public"],
deps = [
"//pkg/cloud/azure:go_default_library",
"//pkg/cloud/azure/actuators:go_default_library",
"//pkg/cloud/azure/services:go_default_library",
"//pkg/cloud/azure/services/certificates:go_default_library",
"//pkg/cloud/azure/services/groups:go_default_library",
"//pkg/cloud/azure/services/network:go_default_library",
"//pkg/cloud/azure/services/internalloadbalancers:go_default_library",
"//pkg/cloud/azure/services/publicips:go_default_library",
"//pkg/cloud/azure/services/publicloadbalancers:go_default_library",
"//pkg/cloud/azure/services/routetables:go_default_library",
"//pkg/cloud/azure/services/securitygroups:go_default_library",
"//pkg/cloud/azure/services/subnets:go_default_library",
"//pkg/cloud/azure/services/virtualnetworks:go_default_library",
"//pkg/deployer:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
Expand All @@ -28,8 +34,9 @@ go_test(
srcs = ["actuator_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/azureprovider/v1alpha1:go_default_library",
"//pkg/cloud/azure:go_default_library",
"//pkg/cloud/azure/actuators:go_default_library",
"//pkg/cloud/azure/services:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1:go_default_library",
],
Expand Down
Loading

0 comments on commit a818b2d

Please sign in to comment.