Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
tolerate multi entries for same subscription
in one OperandRequest

Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan committed Mar 10, 2023
commit 322f0a009ea8c370299bd7ead176bedb254b406a
4 changes: 2 additions & 2 deletions controllers/operandrequest/operandrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@ func (r *Reconciler) getRegistryToRequestMapper() handler.MapFunc {

func (r *Reconciler) getSubToRequestMapper() handler.MapFunc {
return func(object client.Object) []ctrl.Request {
reg, _ := regexp.Compile(`^(.*)\.(.*)\/request`)
reg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/request`)
annotations := object.GetAnnotations()
var reqName, reqNamespace string
for annotation := range annotations {
if reg.MatchString(annotation) {
annotationSlices := strings.Split(annotation, ".")
reqNamespace = annotationSlices[0]
reqName = strings.Split(annotationSlices[1], "/")[0]
reqName = annotationSlices[1]
}
}
if reqNamespace == "" || reqName == "" {
Expand Down
4 changes: 2 additions & 2 deletions controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ func (r *Reconciler) reconcileOperand(ctx context.Context, requestInstance *oper
// find the OperandRequest which has the same operator's channel version as existing subscription.
// ODLM will only reconcile Operand based on OperandConfig for this OperandRequest
var requestList []string
reg, _ := regexp.Compile(`^(.*)\.(.*)\/request`)
reg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/request`)
for anno, version := range sub.Annotations {
if reg.MatchString(anno) && version == sub.Spec.Channel {
requestList = append(requestList, anno)
}
}

if len(requestList) == 0 || !util.Contains(requestList, requestInstance.Namespace+"."+requestInstance.Name+"/request") {
if len(requestList) == 0 || !util.Contains(requestList, requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request") {
klog.V(2).Infof("Subscription %s in the namespace %s is NOT managed by %s/%s, Skip reconciling Operands", sub.Name, sub.Namespace, requestInstance.Namespace, requestInstance.Name)
requestInstance.SetMemberStatus(operand.Name, "", operatorv1alpha1.ServiceRunning, &r.Mutex)
continue
Expand Down
14 changes: 7 additions & 7 deletions controllers/operandrequest/reconcile_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ func (r *Reconciler) reconcileSubscription(ctx context.Context, requestInstance
}
sub.Annotations[registryKey.Namespace+"."+registryKey.Name+"/registry"] = "true"
sub.Annotations[registryKey.Namespace+"."+registryKey.Name+"/config"] = "true"
sub.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"/request"] = opt.Channel
sub.Annotations[requestInstance.Namespace+"."+requestInstance.Name+"."+operand.Name+"/request"] = opt.Channel

sub.Spec.CatalogSource = opt.SourceName
sub.Spec.CatalogSourceNamespace = opt.SourceNamespace
sub.Spec.Package = opt.PackageName

// check request annotation in subscription, get all available channels
var semverlList []string
reg, _ := regexp.Compile(`^(.*)\.(.*)\/request`)
reg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/request`)
for anno, channel := range sub.Annotations {
if reg.MatchString(anno) && semver.IsValid(channel) {
semverlList = append(semverlList, channel)
Expand Down Expand Up @@ -331,11 +331,11 @@ func (r *Reconciler) deleteSubscription(ctx context.Context, operandName string,
// remove request in annotation of subscription
reqName := requestInstance.ObjectMeta.Name
reqNs := requestInstance.ObjectMeta.Namespace
delete(sub.Annotations, reqNs+"."+reqName+"/request")
delete(sub.Annotations, reqNs+"."+reqName+"."+op.Name+"/request")

var semverlList []string
var annoSlice []string
reg, _ := regexp.Compile(`^(.*)\.(.*)\/request`)
reg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/request`)
for anno, channel := range sub.Annotations {
if reg.MatchString(anno) {
annoSlice = append(annoSlice, anno)
Expand Down Expand Up @@ -483,9 +483,9 @@ func (r *Reconciler) generateClusterObjects(o *operatorv1alpha1.Operator, regist
constant.OpreqLabel: "true",
}
annotations := map[string]string{
registryKey.Namespace + "." + registryKey.Name + "/registry": "true",
registryKey.Namespace + "." + registryKey.Name + "/config": "true",
requestKey.Namespace + "." + requestKey.Name + "/request": o.Channel,
registryKey.Namespace + "." + registryKey.Name + "/registry": "true",
registryKey.Namespace + "." + registryKey.Name + "/config": "true",
requestKey.Namespace + "." + requestKey.Name + "." + o.Name + "/request": o.Channel,
}

klog.V(3).Info("Generating Namespace: ", o.Namespace)
Expand Down