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
label length limitation
Signed-off-by: Allen Li <[email protected]>
  • Loading branch information
qpdpQ committed Oct 10, 2024
commit e04a02157cb91af73f61ed2e9422d6b5c332c424
15 changes: 9 additions & 6 deletions controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,22 +473,24 @@ func (m *ODLMOperator) GetClusterServiceVersionList(ctx context.Context, sub *ol

packageName := sub.Spec.Package
csvNamespace := sub.Namespace
labelKey := packageName + "." + csvNamespace
labelKey = util.GetFirstNCharacter(labelKey, 63)

// Get the ClusterServiceVersion list with label operators.coreos.com/packageName.csvNamespace=''
csvList := &olmv1alpha1.ClusterServiceVersionList{}
opts := []client.ListOption{
client.MatchingLabels{fmt.Sprintf("operators.coreos.com/%s.%s", packageName, csvNamespace): ""},
client.MatchingLabels{fmt.Sprintf("operators.coreos.com/%s", labelKey): ""},
client.InNamespace(csvNamespace),
}

if err := m.Reader.List(ctx, csvList, opts...); err != nil {
if apierrors.IsNotFound(err) || len(csvList.Items) == 0 {
klog.V(3).Infof("No ClusterServiceVersion found with label operators.coreos.com/%s.%s", packageName, csvNamespace)
klog.V(3).Infof("No ClusterServiceVersion found with label operators.coreos.com/%s", labelKey)
return nil, nil
}
return nil, errors.Wrapf(err, "failed to list ClusterServiceVersions with label operators.coreos.com/%s.%s", packageName, csvNamespace)
return nil, errors.Wrapf(err, "failed to list ClusterServiceVersions with label operators.coreos.com/%s", labelKey)
} else if len(csvList.Items) > 1 {
klog.Warningf("Multiple ClusterServiceVersions found with label operators.coreos.com/%s.%s", packageName, csvNamespace)
klog.Warningf("Multiple ClusterServiceVersions found with label operators.coreos.com/%s", labelKey)
}

var csvs []*olmv1alpha1.ClusterServiceVersion
Expand Down Expand Up @@ -833,10 +835,11 @@ func (m *ODLMOperator) GetValueRefFromConfigMap(ctx context.Context, instanceTyp
}
return "", errors.Wrapf(err, "failed to get Configmap %s/%s", cmNs, cmName)
}

labelvalue := instanceType + "." + instanceNs + "." + instanceName
labelvalue = util.GetFirstNCharacter(labelvalue, 63)
// Set the Value Reference label for the ConfigMap
util.EnsureLabelsForConfigMap(cm, map[string]string{
constant.ODLMReferenceLabel: instanceType + "." + instanceNs + "." + instanceName,
constant.ODLMReferenceLabel: labelvalue,
constant.ODLMWatchedLabel: "true",
})
// Update the ConfigMap with the Value Reference label
Expand Down
7 changes: 7 additions & 0 deletions controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,10 @@ func addField(obj map[string]interface{}, fields []string, value interface{}) {
// Add the value to the map
addField(obj[fields[0]].(map[string]interface{}), fields[1:], value)
}

func GetFirstNCharacter(str string, n int) string {
if n >= len(str) {
return str
}
return string(str[:n])
}