-
Notifications
You must be signed in to change notification settings - Fork 68
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
Handle the broker in the operator #1085
Conversation
62db248
to
d9b907d
Compare
This PR updates |
d9b907d
to
fb970db
Compare
+1 for operator only for now... |
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
|
||
Components []string `json:"components,omitempty"` |
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.
Thanks for updating last moment, I just realized you were into this too :/
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"` | ||
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"` | ||
DefaultGlobalnetClusterSize uint `json:"defaultGlobalnetClusterSize"` | ||
GlobalnetEnabled bool `json:"globalnetEnabled"` |
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 we make GlobalNetEnabled an optional/omitempty argument?, same for DefaultGlobalnetClusterSize?, is it possible -an alternative- to provide default values and allow omission?
Is it really necessary?, could it be that "GlobalnetCidrRange == GlobalnetEnabled?" (not sure about it though).
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.
How about making Globalnet a component? I’ll try that in a separate PR... Also, Globalnet can be enabled without a CIDR range, can’t it?
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.
Hmm, that'd be rather neat I think @skitt
Without a CIDR range I'm not sure, I guess we need something at least for auto-assignment of clusters. But if you don't want auto-assignment I guess you don't need it @sridhargaddam ^
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.
Correct, the globalCIDR is required for auto-assignment to clusters while the cluster is joining the Broker. We provide flexibility to users to specify custom globalCIDR, but IMO we should continue to have a default CIDR to support clusters that do not explicitly specify globalCIDR while joining.
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 fields are now all optional.
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.
#1102 tracks the componentisation of Globalnet.
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 comments
# globalnetCidrRange: | ||
defaultGlobalnetClusterSize: 8192 |
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.
Is there a way to allow omission of 'defaultGlobanetClusterSize', and also, provide a default value? I guess that can be done in code.
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 is just an example, intended for documentation in the operator when shown in the catalog.
err = broker.Ensure(config) | ||
|
||
status.Start("Setting up broker RBAC") | ||
err = broker.Ensure(config, 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 was expecting that the operator would create the RBAC details too, I guess it's not very secure though, but thinking of usability and the concept of doing it on the operator... it's weird that we would need to setup RBAC manually if not doing it with subctl.
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 discussed this in the past, and decided to forgo dealing with RBAC in the operator, because it requires granting too many privileges to the operator.
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 know, I remember, but I start to see issues with our thinking as we move the broker here too, which is different to just "provide RBAC to submariner services", ... now we need to provide RBAC / Accounts to signed up clusters...
We will need to document the RBAC steps unless we change that.
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 we remove the rbac.go
in favour of working with embedded yaml files?
The yaml files could be tracked in config/rbac
. This way I can use them in the operator bundle.
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.
@SteveMattar this is tracked in #1105.
Sorry, the second batch of comments came separate. |
fb970db
to
ed1f5d2
Compare
ed1f5d2
to
298d9c5
Compare
This needs #1096 first. |
298d9c5
to
a2fb7c8
Compare
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"` | ||
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"` | ||
DefaultGlobalnetClusterSize uint `json:"defaultGlobalnetClusterSize,omitempty"` | ||
GlobalnetEnabled bool `json:"globalnetEnabled,omitempty"` |
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 might require changes to subctl to prompt the user to provide the GlobalnetCIDR/GlobalnetClusterSize while joining a new Cluster, if there are no defaults configured when Broker is deployed.
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 is already the case, I’ll do that in a separate PR. #1103 tracks 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.
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.
Well, or may be not, not sure, if they are going through the process of using the operator directly.... may be it's better to let them be explicit
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 prefer #1104 ;-)
a2fb7c8
to
26907ed
Compare
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"` | ||
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"` | ||
DefaultGlobalnetClusterSize uint `json:"defaultGlobalnetClusterSize,omitempty"` | ||
GlobalnetEnabled bool `json:"globalnetEnabled,omitempty"` |
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.
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.
What about the broker RBAC? Currently the only way it works is by using subctl
.
Should we export these roles to config/rbac
?
config/crd/kustomization.yaml
Outdated
@@ -5,19 +5,22 @@ | |||
resources: | |||
# - bases/submariner.io_servicediscoveries.yaml | |||
- bases/submariner.io_submariners.yaml | |||
# - bases/submariner.io_brokers.yaml |
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.
Do we want to hide this CRD? how do we install the broker when working with the bundle only?
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.
Ah, right, we do want to show the CRD!
if err = (&submariner.BrokerReconciler{ | ||
Client: mgr.GetClient(), | ||
Config: mgr.GetConfig(), | ||
Log: ctrl.Log.WithName("controllers").WithName("Broker"), | ||
Scheme: mgr.GetScheme(), | ||
}).SetupWithManager(mgr); err != nil { | ||
log.Error(err, "unable to create controller", "controller", "Broker") | ||
os.Exit(1) | ||
} |
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 think you can add this function to controllers.AddToManager
this is how we usually start a new Reconciler
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 is what the operator SDK generated for me...
Sorry @skitt just saw the previous comments |
This is what I’d asked you about a couple of weeks ago; I couldn’t get the SDK to generate the appropriate |
Sorry you might have missed my message on slack... the thread is confusing sometimes :) |
Right, that’s what I found out too (which is how I disabled the Broker RBAC handling, see the |
|
||
Components []string `json:"components,omitempty"` | ||
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"` | ||
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"` |
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've been trending from Cidr
-> CIDR
elsewhere...
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"` | |
GlobalnetCIDRRange string `json:"globalnetCIDRRange,omitempty"` |
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.
Ah yes, fixed.
return nil | ||
} | ||
|
||
func createBroker(clientSet submarinerclientset.Interface, namespace string, brokerCR *submarinerv1a1.Broker) (bool, error) { |
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.
Do we need to return bool
here instead of just err
?
_, err := clientSet.SubmarinerV1alpha1().Brokers(namespace).Create(brokerCR) | ||
if err == nil { | ||
return true, nil | ||
} else if errors.IsAlreadyExists(err) { | ||
retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error { | ||
// We can’t always handle existing resources, and we want to overwrite them anyway, so delete them | ||
err := clientSet.SubmarinerV1alpha1().Brokers(namespace).Delete(brokerCR.Name, &metav1.DeleteOptions{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to delete pre-existing cfg %s : %s", brokerCR.Name, err) | ||
} | ||
_, err = clientSet.SubmarinerV1alpha1().Brokers(namespace).Create(brokerCR) | ||
if err != nil { | ||
return fmt.Errorf("failed to create cfg %s : %s", brokerCR.Name, err) | ||
} | ||
return nil | ||
}) | ||
return false, retryErr | ||
} | ||
return false, err |
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 really don't need RetryOnConflict
as it applies to Update. We could refactor to a loop as per below but not a big deal either way. I can add a CreateAnew function in admiral that does the DeleteIfExistsThenCreate pattern.
_, err := clientSet.SubmarinerV1alpha1().Brokers(namespace).Create(brokerCR) | |
if err == nil { | |
return true, nil | |
} else if errors.IsAlreadyExists(err) { | |
retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error { | |
// We can’t always handle existing resources, and we want to overwrite them anyway, so delete them | |
err := clientSet.SubmarinerV1alpha1().Brokers(namespace).Delete(brokerCR.Name, &metav1.DeleteOptions{}) | |
if err != nil { | |
return fmt.Errorf("failed to delete pre-existing cfg %s : %s", brokerCR.Name, err) | |
} | |
_, err = clientSet.SubmarinerV1alpha1().Brokers(namespace).Create(brokerCR) | |
if err != nil { | |
return fmt.Errorf("failed to create cfg %s : %s", brokerCR.Name, err) | |
} | |
return nil | |
}) | |
return false, retryErr | |
} | |
return false, err | |
for { | |
_, err := clientSet.SubmarinerV1alpha1().Brokers(namespace).Create(brokerCR) | |
if err == nil { | |
return nil | |
} | |
if errors.IsAlreadyExists(err) { | |
err := clientSet.SubmarinerV1alpha1().Brokers(namespace).Delete(brokerCR.Name, &metav1.DeleteOptions{}) | |
if err != nil && !errors.IsNotFound(err) { | |
return fmt.Errorf("failed to delete pre-existing Broker instance %q : %v", brokerCR.Name, err) | |
} | |
continue | |
} | |
return err | |
} | |
return nil |
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.
Ah yes, a creation can never return an error which RetryOnConflict will recognise as a conflict. We’d really have to loop ourselves, with a backoff...
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’ll submit an appropriate function for Admiral tomorrow.)
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 actually working on that 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.
92e551b
to
f33cf2d
Compare
@@ -34,7 +34,7 @@ import ( | |||
"k8s.io/client-go/rest" | |||
) | |||
|
|||
func Ensure(config *rest.Config) error { |
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.
Why is the crds bool added, where is it used? :-?
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.
Oops, something got lost in a rebase it seems...
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 restored.
Fixes: submariner-io#203 Signed-off-by: Stephen Kitt <[email protected]>
f33cf2d
to
f29f66b
Compare
Fixes: #203
Signed-off-by: Stephen Kitt [email protected]