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

Handle the broker in the operator #1085

Merged
merged 1 commit into from
Feb 23, 2021

Conversation

skitt
Copy link
Member

@skitt skitt commented Feb 12, 2021

Fixes: #203
Signed-off-by: Stephen Kitt [email protected]

@skitt skitt requested a review from SteveMattar February 12, 2021 16:23
@skitt skitt force-pushed the broker-operator branch 2 times, most recently from 62db248 to d9b907d Compare February 17, 2021 09:01
@skitt
Copy link
Member Author

skitt commented Feb 17, 2021

This PR updates subctl so that deploy-broker goes through the operator, but it doesn’t remove all the non-operator-based code — I’m wondering whether we should add a flag to allow broker deployment without the operator, or if we should just forget that and only support the operator.

@mangelajo
Copy link
Contributor

This PR updates subctl so that deploy-broker goes through the operator, but it doesn’t remove all the non-operator-based code — I’m wondering whether we should add a flag to allow broker deployment without the operator, or if we should just forget that and only support the operator.

+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"`
Copy link
Contributor

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"`
Copy link
Contributor

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).

Copy link
Member Author

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?

Copy link
Contributor

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 ^

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

@mangelajo mangelajo left a comment

Choose a reason for hiding this comment

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

Some comments

Comment on lines 7 to 8
# globalnetCidrRange:
defaultGlobalnetClusterSize: 8192
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

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.

Copy link
Member Author

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.

pkg/subctl/operator/brokercr/ensure.go Outdated Show resolved Hide resolved
pkg/subctl/operator/submarinerop/crds/ensure.go Outdated Show resolved Hide resolved
@mangelajo
Copy link
Contributor

Sorry, the second batch of comments came separate.

@skitt
Copy link
Member Author

skitt commented Feb 17, 2021

This needs #1096 first.

@skitt skitt marked this pull request as draft February 17, 2021 17:48
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"`
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"`
DefaultGlobalnetClusterSize uint `json:"defaultGlobalnetClusterSize,omitempty"`
GlobalnetEnabled bool `json:"globalnetEnabled,omitempty"`
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer #1104 ;-)

@skitt skitt marked this pull request as ready for review February 22, 2021 08:19
pkg/subctl/operator/brokercr/ensure.go Outdated Show resolved Hide resolved
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"`
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"`
DefaultGlobalnetClusterSize uint `json:"defaultGlobalnetClusterSize,omitempty"`
GlobalnetEnabled bool `json:"globalnetEnabled,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

@SteveMattar SteveMattar left a 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?

@@ -5,19 +5,22 @@
resources:
# - bases/submariner.io_servicediscoveries.yaml
- bases/submariner.io_submariners.yaml
# - bases/submariner.io_brokers.yaml

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?

Copy link
Member Author

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!

Comment on lines +212 to +220
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)
}

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

Copy link
Member Author

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...

@SteveMattar
Copy link

Sorry @skitt just saw the previous comments

@skitt
Copy link
Member Author

skitt commented Feb 22, 2021

What about the broker RBAC? Currently the only way it works is by using subctl.
Should we export these roles to config/rbac?

This is what I’d asked you about a couple of weeks ago; I couldn’t get the SDK to generate the appropriate role.yaml file, or rather, I could, but it overwrote all the existing RBAC setup that’s in there.

@SteveMattar
Copy link

What about the broker RBAC? Currently the only way it works is by using subctl.
Should we export these roles to config/rbac?

This is what I’d asked you about a couple of weeks ago; I couldn’t get the SDK to generate the appropriate role.yaml file, or rather, I could, but it overwrote all the existing RBAC setup that’s in there.

Sorry you might have missed my message on slack... the thread is confusing sometimes :)
I'll just drop my comment here:
"I found the problem... when controller-gen generates the rbac manifests the default output is config/rbac/role.yaml but the +kubebuilder:rbac markers for submariner and servicediscovery never worked... The reason is because there is a missing empty line between those markers and the class definition. That means the role.yaml file was never updated."

@skitt
Copy link
Member Author

skitt commented Feb 22, 2021

What about the broker RBAC? Currently the only way it works is by using subctl.
Should we export these roles to config/rbac?

This is what I’d asked you about a couple of weeks ago; I couldn’t get the SDK to generate the appropriate role.yaml file, or rather, I could, but it overwrote all the existing RBAC setup that’s in there.

Sorry you might have missed my message on slack... the thread is confusing sometimes :)
I'll just drop my comment here:
"I found the problem... when controller-gen generates the rbac manifests the default output is config/rbac/role.yaml but the +kubebuilder:rbac markers for submariner and servicediscovery never worked... The reason is because there is a missing empty line between those markers and the class definition. That means the role.yaml file was never updated."

Right, that’s what I found out too (which is how I disabled the Broker RBAC handling, see the TODO there). I hesitated to re-enable the full RBAC handling because it produces ClusterRoles, not Roles as we currently have...


Components []string `json:"components,omitempty"`
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"`
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"`
Copy link
Contributor

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...

Suggested change
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"`
GlobalnetCIDRRange string `json:"globalnetCIDRRange,omitempty"`

Copy link
Member Author

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) {
Copy link
Contributor

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?

Comment on lines 58 to 76
_, 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
Copy link
Contributor

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.

Suggested change
_, 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

Copy link
Member Author

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...

Copy link
Member Author

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.)

Copy link
Contributor

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 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

@skitt skitt force-pushed the broker-operator branch 7 times, most recently from 92e551b to f33cf2d Compare February 23, 2021 09:58
@@ -34,7 +34,7 @@ import (
"k8s.io/client-go/rest"
)

func Ensure(config *rest.Config) error {
Copy link
Contributor

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? :-?

Copy link
Member Author

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...

Copy link
Member Author

Choose a reason for hiding this comment

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

Now restored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move broker handling to the operator (out of subctl)
5 participants