-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
34d8bc4
to
ec6b1a9
Compare
There was a problem hiding this 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.
pkg/comp-functions/functions/vshn-postgres-func/loadBalancer.go
Outdated
Show resolved
Hide resolved
pkg/comp-functions/functions/vshn-postgres-func/loadBalancer.go
Outdated
Show resolved
Hide resolved
ec6b1a9
to
8b39edd
Compare
@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 |
There was a problem hiding this 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.
}, | ||
} | ||
|
||
// if there is nothin to do, return early |
There was a problem hiding this comment.
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
pkg/comp-functions/functions/vshn-postgres-func/loadBalancer.go
Outdated
Show resolved
Hide resolved
Type: pointer.String("LoadBalancer"), | ||
}, | ||
} | ||
err = iof.Desired.PutIntoObject(ctx, cluster, "cluster") |
There was a problem hiding this comment.
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.
Co-authored-by: Kidswiss <[email protected]>
@@ -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 |
There was a problem hiding this comment.
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...) | ||
} | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
@Kidswiss All changes You requested pushed with latest commit, please take a look, I'll also update component-appcat to reflect new config parameter |
@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. |
There was a problem hiding this 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
Co-authored-by: Kidswiss <[email protected]>
…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]>
Summary
Checklist
bug
,enhancement
,documentation
,change
,breaking
,dependency
as they show up in the changelog