Skip to content

Commit

Permalink
Add label selector support to DIM (#1371)
Browse files Browse the repository at this point in the history
* Add label selector support to DIM

* Update DIM CRD
  • Loading branch information
dymurray committed Jun 4, 2024
1 parent a7379f7 commit 2a6dee1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
46 changes: 46 additions & 0 deletions config/crds/migration.openshift.io_directimagemigrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,52 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
labelSelector:
description: LabelSelector optional label selector on the included
resources to migrate
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
namespaces:
description: Holds names of all namespaces to run DIM to get all the
imagestreams in these namespaces.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/migration/v1alpha1/directimagemigration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type DirectImageMigrationSpec struct {

// Holds names of all namespaces to run DIM to get all the imagestreams in these namespaces.
Namespaces []string `json:"namespaces,omitempty"`

// LabelSelector optional label selector on the included resources to migrate
// +kubebuilder:validation:Optional
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
}

// DirectImageMigrationStatus defines the observed state of DirectImageMigration
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/directimagemigration/imagestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ func (t *Task) listImageStreams() error {
var isRefList []*migapi.ImageStreamListItem
// Get list namespaces to iterate over
for srcNsName, destNsName := range t.Owner.GetNamespaceMapping() {
labels, _ := metav1.LabelSelectorAsSelector(t.Owner.Spec.LabelSelector)
isList := imagev1.ImageStreamList{}
err := srcClient.List(
context.TODO(),
&isList,
k8sclient.InNamespace(srcNsName))
k8sclient.InNamespace(srcNsName),
k8sclient.MatchingLabelsSelector{Selector: labels},
)
if err != nil {
return liberr.Wrap(err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/migmigration/directimagemigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (t *Task) buildDirectImageMigration() *migapi.DirectImageMigration {
SrcMigClusterRef: t.PlanResources.MigPlan.Spec.SrcMigClusterRef,
DestMigClusterRef: t.PlanResources.MigPlan.Spec.DestMigClusterRef,
Namespaces: t.PlanResources.MigPlan.Spec.Namespaces,
LabelSelector: t.PlanResources.MigPlan.Spec.LabelSelector,
},
}
migapi.SetOwnerReference(t.Owner, t.Owner, dim)
Expand Down

0 comments on commit 2a6dee1

Please sign in to comment.