Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to CRDS and Kube builder #33

Merged
merged 52 commits into from
Dec 10, 2018
Merged

Migrate to CRDS and Kube builder #33

merged 52 commits into from
Dec 10, 2018

Conversation

marwanad
Copy link
Member

@marwanad marwanad commented Nov 16, 2018

The diff is massive but going commit by commit should describe the migration flow.

Closes #8

azure-pipelines.yml Outdated Show resolved Hide resolved
unused-packages = true

[[prune.project]]
Copy link
Member Author

@marwanad marwanad Nov 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling pruning for the cluster-api project to keep the sigs.k8s/cluster-api/config folder which is needed for applying the CRDs.

apiVersion: "cluster.k8s.io/v1alpha1"
kind: Cluster
metadata:
name: $CLUSTER_NAME
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use the generated cluster name

@@ -0,0 +1,36 @@
apiVersion: apiextensions.k8s.io/v1beta1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generated by kubebuilder

os.Exit(1)
}

clusterActuator, err := cluster.NewClusterActuator(cluster.ClusterActuatorParams{Client: mgr.GetClient()})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creates the actuator and registers them

if azure.client == nil {
return nil, nil
}
currentMachine, err := util.GetMachineIfExists(azure.client, m.ObjectMeta.Namespace, m.ObjectMeta.Name)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API changed upstream

if err != nil {
return err
}
return azure.client.Update(context.Background(), m)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API changed upstream

}
}

// func TestUpdateNoSpecChange(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fake client was removed upstream so need to revisit unit testing this part.

ports:
- port: 443
---
apiVersion: apps/v1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic is from the provider-components template with the un-used fields removed.

@marwanad marwanad changed the base branch from machine-actuator-update to master November 27, 2018 02:25
@marwanad marwanad force-pushed the migrate-to-crd-kubebuilder branch from 90c93e5 to 129dfde Compare November 27, 2018 02:55
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager github.com/platform9/azure-provider/cmd/manager

# Copy the controller-manager into a thin image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is alpine 3.8 possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup - it should be. The file was generated using kube-builder and I think it defaulted to ubuntu.

return nil, nil
}
currentMachine, err := util.GetMachineIfExists(azure.client, m.ObjectMeta.Namespace, m.ObjectMeta.Name)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err != nil {
if err != nil || currentMachine == nil {

Can we merge the two if loops using that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the two checks to differentiate between the cases when the machine is actually because it has been deleted and just erroring on attempting to call the query the clients to check for machine existence.

Can we merge them in a way without losing that info?

return nil
}
currentMachine, err := util.GetMachineIfExists(azure.client, machine.ObjectMeta.Namespace, machine.ObjectMeta.Name)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment

}

func (azure *AzureClient) updateAnnotations(cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
if azure.client == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure how I feel about these nil pre-checks at the beginning of a method.I would avoid this by having a nil check / validation much earlier in the call stack so that we don't do them over here. I may not have the complete context here of course. Open to discussing more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was mostly left there for testing. But we can just initialize the actuator in the tests using the fake client. I'll get rid of those checks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this change would require us to update the controller-runtime revision to pickup this change: https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/client/fake/client.go#L57 for the unit tests to pass.

I'd say we wait on this to reduce the scope of this PR.

@@ -0,0 +1,235 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocks !!! YAY!. Great going @marwanad :)

if err != nil {
return fmt.Errorf("error creating or updating network security group: %v", err)
}
err = azure.network().WaitForNetworkSGsCreateOrUpdateFuture(*networkSGFuture)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move to azure.network() to a variable and reuse that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method network() is just a wrapper that returns azure.services.Network. It doesn't recreate the clients or anything but I can switch it over to local variables if you think that's better for readability.

if err != nil {
return fmt.Errorf("error loading cluster provider config: %v", err)
}
resp, err := azure.resourcemanagement().CheckGroupExistence(clusterConfig.ResourceGroup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move azure.resourcemanagement() and reuse that?

Suggested change
resp, err := azure.resourcemanagement().CheckGroupExistence(clusterConfig.ResourceGroup)
azResourceClient := azure.resourcemanagement()

@marwanad marwanad force-pushed the migrate-to-crd-kubebuilder branch from 2dd6a73 to ab655ce Compare December 6, 2018 00:10
Copy link

@ok-to-test ok-to-test left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall. I apologize for the not keeping up with the updates here. Thanks for keeping the tests up to date. I'll get this merged asap to prevent this PR from getting bigger.

@vannrt
Copy link
Contributor

vannrt commented Dec 10, 2018

@ok-to-test Is an account I made for testing some webhooks.

Copy link
Contributor

@vannrt vannrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @marwanad

@vannrt vannrt merged commit 9906ecd into master Dec 10, 2018
@cblecker cblecker deleted the migrate-to-crd-kubebuilder branch January 10, 2019 00:29
luthermonson pushed a commit to luthermonson/cluster-api-provider-azure that referenced this pull request Jul 7, 2022
* added auto-scaling support for azure

* changes to allow creationg of autoscaling machine pool during creation of AKS cluster
satviksr-db pushed a commit to databricks/cluster-api-provider-azure-1 that referenced this pull request Nov 10, 2023
[ES-569654] Remove agent pool profiles from managed cluster update request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants