-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: stoneshi-yunify <[email protected]>
- Loading branch information
1 parent
081b266
commit 5a35bf3
Showing
13 changed files
with
463 additions
and
454 deletions.
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,16 @@ | ||
{ | ||
"target": { | ||
"path": { | ||
"deployment": "volume-initializer" | ||
}, | ||
"namespace": "default" | ||
}, | ||
"feature": { | ||
"network": { | ||
"incoming": "steal", | ||
"outgoing": true | ||
}, | ||
"fs": "read", | ||
"env": true | ||
} | ||
} |
610 changes: 200 additions & 410 deletions
610
config/crd/bases/storage.kubesphere.io_initializers.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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,71 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"slices" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
const ( | ||
FieldName = "name" | ||
FieldNamespace = "namespace" | ||
) | ||
|
||
// GenericSelector supports field selector and label selector, they're ANDed requirements. | ||
type GenericSelector struct { | ||
// FieldSelector is the field selector, which only supports "name" and "namespace" as key, and "In" and "NotIn" as operator. | ||
FieldSelector []metav1.FieldSelectorRequirement `json:"fieldSelector,omitempty"` | ||
|
||
// LabelSelector is the label selector | ||
LabelSelector []metav1.LabelSelectorRequirement `json:"labelSelector,omitempty"` | ||
} | ||
|
||
func (s *GenericSelector) Match(obj metav1.Object) bool { | ||
for _, req := range s.FieldSelector { | ||
if req.Key != FieldName && req.Key != FieldNamespace { | ||
continue | ||
} | ||
if req.Operator != metav1.FieldSelectorOpIn && req.Operator != metav1.FieldSelectorOpNotIn { | ||
continue | ||
} | ||
|
||
var val string | ||
if req.Key == FieldName { | ||
val = obj.GetName() | ||
} | ||
if req.Key == FieldNamespace { | ||
val = obj.GetNamespace() | ||
} | ||
|
||
var match bool | ||
if req.Operator == metav1.FieldSelectorOpIn { | ||
match = slices.Contains(req.Values, val) | ||
} | ||
if req.Operator == metav1.FieldSelectorOpNotIn { | ||
match = !slices.Contains(req.Values, val) | ||
} | ||
|
||
if !match { | ||
return false | ||
} | ||
} | ||
|
||
if len(s.LabelSelector) > 0 { | ||
labelSelector := metav1.LabelSelector{ | ||
MatchExpressions: s.LabelSelector, | ||
} | ||
selector, err := metav1.LabelSelectorAsSelector(&labelSelector) | ||
if err != nil { | ||
klog.ErrorS(err, "LabelSelectorAsSelector", "labelSelector", labelSelector) | ||
return false | ||
} | ||
match := selector.Matches(labels.Set(obj.GetLabels())) | ||
if !match { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
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.