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

Added CivoNetwork Support #57

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Added CivoNetwork Support #57

wants to merge 20 commits into from

Conversation

uzaxirr
Copy link
Collaborator

@uzaxirr uzaxirr commented Mar 23, 2024

Description of your changes

Fixes #

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

@uzaxirr uzaxirr added the enhancement New feature or request label Mar 23, 2024
@uzaxirr uzaxirr self-assigned this Mar 23, 2024
@uzaxirr uzaxirr changed the title Added CivoNetwork Specs Added CivoNetwork Support Mar 26, 2024
NameServersV4 []string `json:"nameservers_v4"`

// Details regarding current state of the bucket.
Conditions []metav1.Condition `json:"conditions"`
Copy link
Collaborator

@RealHarshThakur RealHarshThakur Mar 26, 2024

Choose a reason for hiding this comment

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

Do we need this again or can we re-use the ones Crossplane gives us?

ID string `json:"id"`
Name string `json:"name"`
Default bool `json:"default"`
CIDR string `json:"cidr"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lot of these fields belong in the spec, not Observation like CIDR, Nameservers, Label

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Go SDK accepts only labels as a param while creating a network, CIDR, Nameservers and all cannot be passed

@uzaxirr
Copy link
Collaborator Author

uzaxirr commented Mar 26, 2024

Screenshot 2024-03-26 at 4 14 13 PM

// CivoNetworkObservation are the observable fields of a CivoNetwork.
type CivoNetworkObservation struct {
ID string `json:"id"`
Name string `json:"name"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name is repeated ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, Name and label are two diff things

    {
        "id": "2d2febbd-8a93-45ea-923f-936c8449611c",
        "name": "cust-default-d3daf04d-7505ea9087ce",
        "default": true,
        "cidr": "192.168.1.0/24",
        "label": "default",
        "status": "Active",
        "ipv4_enabled": true,
        "nameservers_v4": [
            "8.8.8.8",
            "1.1.1.1"
        ]
    },

ID string `json:"id"`
Name string `json:"name"`
Default bool `json:"default"`
Label string `json:"label"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Description on fields is missing. What is the difference between Label and Name?

@@ -20,10 +20,12 @@ import (
"os"
"path/filepath"

"github.com/crossplane-contrib/provider-civo/internal/controller/civonetwork"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import order should be std, 3rd party, local pacakges.

go.mod Outdated
@@ -3,7 +3,7 @@ module github.com/crossplane-contrib/provider-civo
go 1.22

require (
github.com/civo/civogo v0.2.68
github.com/civo/civogo v0.3.28
Copy link
Collaborator

Choose a reason for hiding this comment

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

.65 seems to be latest

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

.65 have that KubernetesPoolConfig issue. I'll fix that in a sepearate PR

return managed.ExternalObservation{}, errors.New(errNotCivoNetwork)
}
civoNetwork, err := e.civoClient.GetNetwork(cr.Spec.Name)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There could be a networking issue on client side that leads to failure of getting network details. We should check for the error API returns when Network is not found explicitly.

}

switch civoNetwork.Status {
case NetworkActive:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If Network is active- what happens when user updates the NameServers ? Sending ResourceUpToUpdate will mean that Update won't be triggered at all.

return managed.ExternalCreation{}, nil
}
_, err = e.civoClient.CreateNewNetwork(cr.Spec.Name, cr.Spec.CIDRv4, cr.Spec.NameserversV4)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should check for the error here and if the error says Network Already exists, we should not return an error.

return managed.ExternalCreation{}, errors.New(errNotCivoNetwork)
}
civoNetwork, err := e.civoClient.GetNetwork(cr.Spec.Name)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't follow- on the first try, isn't this always going to error out as the network won't exist and Civo API would complaint it doesn't exist?

if !ok {
return managed.ExternalUpdate{}, errors.New(errNotCivoNetwork)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should check for fields like Nameservers and name/label are changed and update them to desired state.

}
cr.SetConditions(xpv1.Deleting())
err := e.civoClient.DeleteNetwork(cr.Status.AtProvider.ID)
return errors.Wrap(err, errDeleteNetwork)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the error here is NetworkNotFound , we should return nil.

func (c *CivoClient) GetNetwork(id string) (*civogo.Network, error) {
network, err := c.civoGoClient.GetNetwork(id)
if err != nil {
if strings.Contains(err.Error(), "DatabaseNetworkNotFoundError") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should do this here. We should also wrap the error in Error struct that civogo provides and use that but in controllers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

imo its better to handle and return proper errors from the cli.go itself to avoid making contriollers bulky. controllers just have to calls functions in the cli

Signed-off-by: uzair <uzaxirr@gmail.com>
uzaxirr and others added 9 commits April 7, 2024 05:43
Signed-off-by: uzair <uzaxirr@gmail.com>
Signed-off-by: uzair <uzaxirr@gmail.com>
Signed-off-by: uzair <uzaxirr@gmail.com>
Signed-off-by: uzair <uzaxirr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants