-
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 PDB #204
Conversation
} | ||
pdb, ok := obj.(PDB) | ||
if !ok { | ||
return runtime.NewWarningResult(fmt.Sprintf("Type %s doesn't implement PDB interface", reflect.TypeOf(obj).String())) |
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'd also return a fatal here, as that's an error that could only happen if the XRD is wrongly implemented.
emptyMap := map[string]string{} | ||
|
||
// to add new case, simply print labels, for example `kubectl -n vshn-mariadb-something-123sa get pod mariadb-something-123sa-0 -o json | jq .metadata.labels` and add the label to the map | ||
switch obj.(type) { |
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 won't scale, ideally the comp should know the necessary labels and return them as part of the PDB
interface.
case *v1.VSHNKeycloak: | ||
emptyMap["app.kubernetes.io/name"] = obj.GetLabels()["crossplane.io/composite"] | ||
case *v1.VSHNPostgreSQL: | ||
emptyMap["stackgres.io/cluster-name"] = obj.GetLabels()["crossplane.io/composite"] + "-pg" |
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.
For nested services using obj.GetLabels()["crossplane.io/composite"]
will be very problematic as it will always point to the composite belonging to the claim, which might be another service like nextcloud and thus have another name. For example, the -pg
appendix you have here only applies to PG instances that are nested with Nextcloud or Keycloak. A normal PostgreSQL instance doesn't have that appendix.
Just use obj.GetName()
that will return the right value because obj
is our composite anyway.
Co-authored-by: Kidswiss <[email protected]>
Co-authored-by: Kidswiss <[email protected]>
return runtime.NewFatalResult(fmt.Errorf("can't get composite: %w", err)) | ||
} | ||
pdb, ok := comp.(PDB) | ||
if !ok { |
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.
It would be great to catch this problem at build time and not at runtime. I thought about a solution here but nothing comes into my mind. @Kidswiss maybe you have an idea here?
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 tried to think of something during my first review, unfortunately I wasn't able to get a working idea.
I'll have another look now that all my other remarks have been implemented.
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.
Huh... okay it's actually rather simple:
Make the PDB
interface also implement client.Object
:
type PDB interface {
GetInstanceNamespace() string
GetInstances() int
GetPDBLabels() map[string]string
client.Object
}
Accept PDB
in the AddPDBSettings
function:
func AddPDBSettings(comp PDB) func(ctx context.Context, svc *runtime.ServiceRuntime) *fnproto.Result {
Remove the type assert and rename all pdb
variables to comp
. No more type assertion needed and the compiler will scream at you if you forget to implement the interface.
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.
perfect. Awesome. Thanks for this :)
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.
the whole point I wanted to keep it in different interface was that not all services are ready for HA from the beginning, not all services even have a field instances
in their claim. Now it's using InfoGetter{} as mentioned in the beginning and I completely got rid of PDB{} interface
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.
The idea of my comment wasn't to get rid of the PDB
interface completely, just reduce the amount of duplication.
not all services even have a field instances in their claim.
In the long run we want all our service to have HA as well.
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.
@wejdross you can use the interface Composite
here, it will satisfy all necessary functions. Then you can get rid of the type assertion.
@@ -324,3 +324,9 @@ func (v *VSHNKeycloak) GetMonitoring() VSHNMonitoring { | |||
func (v *VSHNKeycloak) GetInstances() int { | |||
return v.Spec.Parameters.Instances | |||
} | |||
|
|||
func (v *VSHNKeycloak) GetPDBLabels() map[string]string { |
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.
Can you please add this to hack/bootstrap/template/api.txt
?
I've added a comment how to make it work: #204 (comment) |
Since you get already the PDB object in the function there's no need to check for anything else at runtime. It should work and in worse case scenario (which should not happen) the application will panick |
1f12158
to
ab32f1e
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.
Now looks great and clean
} | ||
log.Info("HA detected, adding pdb", "service", comp.GetName()) | ||
|
||
min := intstr.IntOrString{IntVal: int32(comp.GetInstances()) / 2} |
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'm not sure this will work for uneven numbers.
- I get this warning in my IDE for variable min:
Inspection info: Reports declarations of variables, arguments or functions that overlap with the built-in or reserved keyword.
If you receive this error then your code might not be as explicit as possible and might confuse other users.
Example:
type byte struct{}
type string interface{}
Types byte and string collide with the built-in type aliases. Therefore, they will be highlighted. Consider renaming such declarations
Maybe the reason why 50% does not work because of the 2 point?
} | ||
log.Info("HA detected, adding pdb", "service", comp.GetName()) | ||
|
||
min := intstr.IntOrString{IntVal: int32(comp.GetInstances()) / 2} |
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.
If the string doesn't work, can we at least make sure that we always round up here? Then we'll have the same functionality as using 50%
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.
ok, I found the issue with 50%
, Type: intval is default one, when setting a strVal: "50%", You must add explicitly Type: strVal
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.
Needs a bit more rework
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.
From my side now it's ok. Please resolve all Simon's concerns and make sure you don't go back to casting approach.
Summary
Checklist
bug
,enhancement
,documentation
,change
,breaking
,dependency
as they show up in the changelog