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

Add external connection IPs to connection secret if service type is set to LoadBalancer for PostgreSQL Managed by VSHN #46

Merged
merged 19 commits into from
Aug 8, 2023

Conversation

wejdross
Copy link
Member

Summary

  • Added new field under spec.parameters.network called ServiceType, if it's set to LoadBalancer, while defaulting to ClusterIP, comp-function starts and add 2 ip addresses to connection secret allowing to access cluster externally without port-forwarding
  • tested with metallb and kind cluster
  • it must spawn in-cluster k8s client and check for services in specific namespace to grab IP addresses

Checklist

  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking, dependency
    as they show up in the changelog
  • [-] Update tests.
  • Link this PR to related issues.

Copy link
Contributor

@Kidswiss Kidswiss left a comment

Choose a reason for hiding this comment

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

We should be really careful about using the kubeclient directly. Crossplane themselves advice us to not do that. See my comment for more details.

@wejdross wejdross requested a review from Kidswiss July 28, 2023 08:41
@wejdross wejdross marked this pull request as draft July 28, 2023 08:44
@wejdross
Copy link
Member Author

@Kidswiss I converted it into draft, please take a look, I'll write some tests in meanwhile, so far I tested it manually and it works pretty well locally

Copy link
Contributor

@Kidswiss Kidswiss left a comment

Choose a reason for hiding this comment

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

I've added a comment on how to properly instruct provider-kubernetes to observe an object.

I guess if we keep using this more and more we could add that as a function to the runtime library.

README.md Outdated Show resolved Hide resolved
},
}

// if there is nothin to do, return early
Copy link
Contributor

Choose a reason for hiding this comment

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

You could move this before line 28

Type: pointer.String("LoadBalancer"),
},
}
err = iof.Desired.PutIntoObject(ctx, cluster, "cluster")
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put the creation of the objects into their own functions. Makes the flow of the logic easier to follow.

For example updateClusterWithLoadbalancer or addServiceObserver. You can check out https://github.com/vshn/appcat/blob/master/pkg/comp-functions/functions/vshnredis/backup.go#L32 for a nice example.

@wejdross wejdross added the enhancement New feature or request label Aug 2, 2023
@wejdross wejdross requested a review from Kidswiss August 3, 2023 09:20
@wejdross wejdross marked this pull request as ready for review August 3, 2023 09:21
@@ -69,8 +69,16 @@ func (d *DesiredResources) GetFromObject(ctx context.Context, o client.Object, k
return d.fromKubeObject(ctx, ko, o)
}

// PutIntoObject adds or updates the desired resource into its kube object
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't remove this comment.

func (d *DesiredResources) PutIntoObject(ctx context.Context, o client.Object, kon string, refs ...xkube.Reference) error {
return d.putIntoObject(ctx, false, o, kon, refs...)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This one should also have a comment.

cmd/grpc.go Outdated
Network = "unix"
AddressFlag = "@crossplane/fn/default.sock"
DevMode = false
ExternalConnectionEnabled = false
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't pass this as a flag.

We usually have these configurations in the composition itself in the config: https://github.com/vshn/component-appcat/blob/master/component/vshn_postgres.jsonnet#L849

They are dynamic and can even be set per composition, this makes them a lot more flexible. You can access the configs via iof.Config in the compisition function.

cmd/grpc.go Outdated
@@ -137,6 +139,12 @@ func (s *server) RunFunction(ctx context.Context, in *pb.RunFunctionRequest) (*p
if err != nil {
return nil, status.Errorf(codes.Aborted, "cannot enable devMode: %s", err)
}
if ExternalConnectionEnabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of conditionally adding this, just add it to the list like all other functions.

Then the first thing you do in the function is checking if the loadbalancer config is enabled or not and either just return or run the function.

@wejdross
Copy link
Member Author

wejdross commented Aug 4, 2023

@Kidswiss All changes You requested pushed with latest commit, please take a look, I'll also update component-appcat to reflect new config parameter

@Kidswiss
Copy link
Contributor

Kidswiss commented Aug 7, 2023

@wejdross please re-request reviews when I should have another look. Then it pops up in https://github.com/pulls/review-requested. Then I should hopefully not miss it :)

Having a look now.

Copy link
Contributor

@Kidswiss Kidswiss left a comment

Choose a reason for hiding this comment

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

Some small things, the rest LGTM

README.md Show resolved Hide resolved
pkg/comp-functions/runtime/desired.go Show resolved Hide resolved
pkg/comp-functions/runtime/runtime.go Outdated Show resolved Hide resolved
@wejdross wejdross merged commit a551592 into master Aug 8, 2023
3 checks passed
TheBigLee pushed a commit that referenced this pull request Aug 18, 2023
…et to LoadBalancer for PostgreSQL Managed by VSHN (#46)

* adding comp-function to manage external IPs in connection secret

* adding comp-function to manage external IPs in connection secret

* adding docs how to run gRPC locally

* new logic for LoadBalancer comp-func

* adding tests

* Update README.md

Co-authored-by: Kidswiss <[email protected]>

* Update pkg/comp-functions/runtime/desired.go

Co-authored-by: Kidswiss <[email protected]>

* refactored code, working, tests passing

* refactoring code

* refactoring code

* reusing config instead of cmdline params

* fixing old tests, adding new test case

* Update pkg/comp-functions/runtime/desired.go

Co-authored-by: Kidswiss <[email protected]>

* adding PR suggestions

* adding PR suggestions

* renaming function

* renaming function

---------

Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Kidswiss <[email protected]>
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