-
Notifications
You must be signed in to change notification settings - Fork 35
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
[ovn-controller] Don't create ovn-controller ds if no NicMappings set #337
Closed
averdagu
wants to merge
1
commit into
openstack-k8s-operators:main
from
averdagu:fix/OSPRH-7463-NicMappings
+671
−201
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: k8s.cni.cncf.io/v1 | ||
kind: NetworkAttachmentDefinition | ||
metadata: | ||
annotations: | ||
labels: | ||
osp/net: kuttlospbr | ||
service: ovn-controller | ||
name: principal | ||
spec: | ||
config: | | ||
{ | ||
"cniVersion": "0.3.1", | ||
"name": "kuttlospbr", | ||
"type": "bridge", | ||
"bridge": "ospbr", | ||
"ipam": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: nmstate.io/v1 | ||
kind: NodeNetworkConfigurationPolicy | ||
metadata: | ||
labels: | ||
osp/interface: enp6s0 | ||
name: enp6s0-crc | ||
spec: | ||
desiredState: | ||
interfaces: | ||
- description: Configuring Bridge | ||
name: osptestbr | ||
mtu: 1500 | ||
type: linux-bridge | ||
state: up | ||
bridge: | ||
options: | ||
stp: | ||
enabled: false | ||
ipv4: | ||
address: | ||
- ip: 192.168.222.10 | ||
prefix-length: 24 | ||
enabled: true | ||
dhcp: false | ||
ipv6: | ||
enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,6 +313,113 @@ func (r *OVNControllerReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Re | |
return ctrl.Result{}, nil | ||
} | ||
|
||
// use lib_commons.daemonset.GetDaemonSetWithName once | ||
// https://github.com/openstack-k8s-operators/lib-common/pull/551 | ||
// is merged | ||
func getDaemonSetWithName( | ||
ctx context.Context, | ||
h *helper.Helper, | ||
name string, | ||
namespace string, | ||
) (*appsv1.DaemonSet, error) { | ||
|
||
dset := &appsv1.DaemonSet{} | ||
err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, dset) | ||
if err != nil { | ||
return dset, err | ||
} | ||
|
||
return dset, nil | ||
} | ||
|
||
func (r *OVNControllerReconciler) ensureCMDeleted( | ||
ctx context.Context, | ||
h *helper.Helper, | ||
instance *ovnv1.OVNController, | ||
) error { | ||
// Delete, if they exist | ||
cms := []string{instance.Name + "-config", instance.Name + "-scripts"} | ||
for _, cmName := range cms { | ||
err := r.deleteConfigMaps(ctx, h, cmName, instance.Namespace) | ||
if err != nil && !k8s_errors.IsNotFound(err) { | ||
return fmt.Errorf("could not delete config map %s: %w", cmName, err) | ||
} | ||
|
||
} | ||
return nil | ||
} | ||
|
||
func ensureDSDeleted( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar nit here too |
||
ctx context.Context, | ||
h *helper.Helper, | ||
instance *ovnv1.OVNController, | ||
) error { | ||
// Delete, if they exist, ovn and ovs ds | ||
daemonsets := []string{"ovn-controller", "ovn-controller-ovs"} | ||
for _, dsName := range daemonsets { | ||
ds, err := getDaemonSetWithName(ctx, h, dsName, instance.Namespace) | ||
if err != nil && !k8s_errors.IsNotFound(err) { | ||
return fmt.Errorf("error getting %s daemonset: %w", dsName, err) | ||
} else if err != nil && k8s_errors.IsNotFound(err) { | ||
// Already deleted | ||
continue | ||
} | ||
|
||
// Delete ds | ||
err = h.GetClient().Delete(ctx, ds) | ||
if err != nil && !k8s_errors.IsNotFound(err) { | ||
return fmt.Errorf("error deleting daemonset %s: %w", ds.Name, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ensureNADDeleted( | ||
ctx context.Context, | ||
h *helper.Helper, | ||
instance *ovnv1.OVNController, | ||
) error { | ||
// Delete NAD if they exist and controller owns it | ||
nadList := &netattdefv1.NetworkAttachmentDefinitionList{} | ||
err := h.GetClient().List(ctx, nadList) | ||
if err != nil { | ||
return fmt.Errorf("error getting NAD list: %w", err) | ||
} | ||
for _, currentNAD := range nadList.Items { | ||
owners := currentNAD.GetOwnerReferences() | ||
// if owners len is only one, means that if ovn controller is the owner we can | ||
// delete it | ||
if len(owners) == 1 { | ||
if owners[0].Name == instance.Name { | ||
err = h.GetClient().Delete(ctx, ¤tNAD) | ||
if err != nil { | ||
return fmt.Errorf("error trying to delete nad %s: %w", currentNAD.Name, err) | ||
} | ||
} | ||
} else if len(owners) > 1 { | ||
// this nad has more than one owner, remove ovn-controller as owner but | ||
// don't delete it | ||
indexToDelete := -1 | ||
for j, owner := range owners { | ||
if owner.Name == instance.Name { | ||
indexToDelete = j | ||
break | ||
} | ||
} | ||
if indexToDelete != -1 { | ||
currentNAD.SetOwnerReferences(append(owners[:indexToDelete], owners[indexToDelete+1:]...)) | ||
err = h.GetClient().Update(ctx, ¤tNAD) | ||
if err != nil { | ||
return fmt.Errorf("error updating NAD %s after ownerReference update: %w", currentNAD.Name, err) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance *ovnv1.OVNController, helper *helper.Helper) (ctrl.Result, error) { | ||
Log := r.GetLogger(ctx) | ||
|
||
|
@@ -339,6 +446,41 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance | |
return rbacResult, nil | ||
} | ||
|
||
// if ovn-controller has no nicMappings, it's useless create daemonset on | ||
// OC nodes, since it won't do anything. | ||
if len(instance.Spec.NicMappings) == 0 { | ||
// Check if DS are created, if so delete the resources associated with it | ||
// Resources associated with ovn-controller: | ||
// - ovncontroller-scripts [cm] | ||
// - ovncontroller-config [cm] | ||
// - ovn-controller [ds] | ||
// - ovn-controller-ovs [ds] | ||
// - job [it gets deleted once it's finished] | ||
err := ensureDSDeleted(ctx, helper, instance) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
err = r.ensureCMDeleted(ctx, helper, instance) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
err = ensureNADDeleted(ctx, helper, instance) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// Set conditions to true as no more work is needed. | ||
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) | ||
instance.Status.Conditions.MarkTrue(condition.InputReadyCondition, condition.InputReadyMessage) | ||
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage) | ||
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) | ||
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage) | ||
instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage) | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
// ConfigMap | ||
configMapVars := make(map[string]env.Setter) | ||
|
||
|
@@ -687,6 +829,28 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance | |
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *OVNControllerReconciler) deleteConfigMaps( | ||
ctx context.Context, | ||
h *helper.Helper, | ||
name string, | ||
namespace string, | ||
) error { | ||
serviceCM := &corev1.ConfigMap{} | ||
err := h.GetClient().Get(ctx, types.NamespacedName{Name: name, Namespace: namespace}, serviceCM) | ||
if err != nil && !k8s_errors.IsNotFound(err) { | ||
return err | ||
} else if k8s_errors.IsNotFound(err) { | ||
return nil | ||
} | ||
|
||
err = h.GetClient().Delete(ctx, serviceCM) | ||
if err != nil && !k8s_errors.IsNotFound(err) { | ||
return fmt.Errorf("error deleting config map %s: %w", serviceCM.Name, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// generateServiceConfigMaps - create configmaps which hold scripts and service configuration | ||
func (r *OVNControllerReconciler) generateServiceConfigMaps( | ||
ctx context.Context, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nitty nit: just for readability IMHO this could be named "ensureConfigMapDeleted" :)
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 we end up ensuring the deletion on the ovn-controller I'll modify this func name.