-
Notifications
You must be signed in to change notification settings - Fork 95
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: xuezhaojun <[email protected]>
- Loading branch information
1 parent
e810520
commit 94dcc76
Showing
20 changed files
with
190 additions
and
7 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
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,26 @@ | ||
package helpers | ||
|
||
import ( | ||
"strings" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
operatorv1 "open-cluster-management.io/api/operator/v1" | ||
) | ||
|
||
func FilterClusterAnnotations(annotations map[string]string) map[string]string { | ||
clusterAnnotations := make(map[string]string) | ||
if annotations == nil { | ||
return clusterAnnotations | ||
} | ||
|
||
for k, v := range annotations { | ||
if strings.HasPrefix(k, operatorv1.ClusterAnnotationsKeyPrefix) { | ||
clusterAnnotations[k] = v | ||
} else { | ||
klog.Warningf("annotation %q is not prefixed with %q, it will be ignored", k, operatorv1.ClusterAnnotationsKeyPrefix) | ||
} | ||
} | ||
|
||
return clusterAnnotations | ||
} |
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 helpers | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
operatorv1 "open-cluster-management.io/api/operator/v1" | ||
) | ||
|
||
func TestFilterClusterAnnotations(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
annotations map[string]string | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "empty annotations", | ||
annotations: map[string]string{}, | ||
want: map[string]string{}, | ||
}, | ||
{ | ||
name: "no cluster annotations", | ||
annotations: map[string]string{ | ||
"foo": "bar", | ||
"baz": "qux", | ||
}, | ||
want: map[string]string{}, | ||
}, | ||
{ | ||
name: "one cluster annotation", | ||
annotations: map[string]string{ | ||
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar", | ||
"baz": "qux", | ||
}, | ||
want: map[string]string{ | ||
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar", | ||
}, | ||
}, | ||
{ | ||
name: "multiple cluster annotations", | ||
annotations: map[string]string{ | ||
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar", | ||
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux", | ||
"quux": "corge", | ||
}, | ||
want: map[string]string{ | ||
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar", | ||
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux", | ||
}, | ||
}, | ||
{ | ||
name: "all annotations are cluster annotations", | ||
annotations: map[string]string{ | ||
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar", | ||
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux", | ||
}, | ||
want: map[string]string{ | ||
operatorv1.ClusterAnnotationsKeyPrefix + "foo": "bar", | ||
operatorv1.ClusterAnnotationsKeyPrefix + "baz": "qux", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := FilterClusterAnnotations(tt.annotations); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("FilterClusterAnnotations() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...ement.io/api/crdsv1beta1/0001_00_operator.open-cluster-management.io_klusterlets.crd.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...ement.io/api/operator/v1/0000_00_operator.open-cluster-management.io_klusterlets.crd.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
vendor/open-cluster-management.io/api/operator/v1/types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
vendor/open-cluster-management.io/api/operator/v1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
vendor/open-cluster-management.io/api/operator/v1/zz_generated.swagger_doc_generated.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.