forked from antrea-io/antrea
-
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.
Label Identity replication for multi-cluster NetworkPolicies (antrea-…
…io#3664) This commit is the first part of the multi-cluster stretched network policy implementation. In order to enforce policies globally based on label selections, Antrea MC Service needs to inform each member cluster of all Pod + Namespace label combinations in the ClusterSet. Each unique Pod + Namespace label combination is defined as labelidentity, which is a normalized string calculated based on Pod's own labels and its Namespace labels. A couple of new controllers and CRDs are added, namely: - A label_identity_controller in each member cluster, which watches Pod and Namespace events, and updates ResourceExport of type labelidentity for each unique label identity in the cluster. - A label_identity_export_controller in the leader cluster, which watches for ResourceExports of type labelidentity from all member clusters, dedups the label identities and assigns a unique ID for each for them. It also creates an ResourceImport of type labelidentity object for the combination of each such labelidentity and its assigned ID in the leader cluster. - A label_identity_export_controller in each member cluster, which watches for ResourceImport of type labelidentity events in the leader, and creates a LabelIdentity CRD object in each member cluster for each ResourceImport of type labelidentity. Signed-off-by: Dyanngg <[email protected]> Co-authored-by: wgrayson <[email protected]>
- Loading branch information
Showing
38 changed files
with
2,826 additions
and
82 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
61 changes: 61 additions & 0 deletions
61
multicluster/apis/multicluster/v1alpha1/labelidentity_types.go
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,61 @@ | ||
/* | ||
Copyright 2022 Antrea Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
// +genclient | ||
// +genclient:nonNamespaced | ||
// +kubebuilder:object:root=true | ||
// +kubebuilder:resource:path=labelidentities,scope=Cluster | ||
|
||
// +kubebuilder:printcolumn:name="Label",type=string,JSONPath=`.spec.label`,description="Normalized string of a label identity" | ||
// +kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.spec.id`,description="ID allocated for the label identity by the leader cluster" | ||
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp` | ||
// LabelIdentity is an imported label identity from the ClusterSet. | ||
// For each unique label identity, a LabelIdentity will be created in the member cluster. | ||
type LabelIdentity struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec LabelIdentitySpec `json:"spec,omitempty"` | ||
} | ||
|
||
type LabelIdentitySpec struct { | ||
// Label is the normalized string of a label identity. | ||
// The format of normalized label identity is `ns:(?P<nslabels>(.)*)&pod:(?P<podlabels>(.)*)` | ||
// E.g., `ns:kubernetes.io/metadata.name=kube-system&pod:app=db` | ||
Label string `json:"label,omitempty"` | ||
// ID is the ID allocated for the label identity by the leader cluster. | ||
ID uint32 `json:"id,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// LabelIdentityList contains a list of LabelIdentity. | ||
type LabelIdentityList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []LabelIdentity `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register( | ||
&LabelIdentity{}, | ||
&LabelIdentityList{}, | ||
) | ||
} |
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
98 changes: 98 additions & 0 deletions
98
multicluster/apis/multicluster/v1alpha1/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.
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.