modify the field networkIsolate in workspace
Signed-off-by: Duan Jiong <djduanjiong@gmail.com>
This commit is contained in:
@@ -33,7 +33,7 @@ const (
|
|||||||
// WorkspaceSpec defines the desired state of Workspace
|
// WorkspaceSpec defines the desired state of Workspace
|
||||||
type WorkspaceSpec struct {
|
type WorkspaceSpec struct {
|
||||||
Manager string `json:"manager,omitempty"`
|
Manager string `json:"manager,omitempty"`
|
||||||
NetworkIsolation bool `json:"networkIsolation,omitempty"`
|
NetworkIsolation *bool `json:"networkIsolation,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkspaceStatus defines the observed state of Workspace
|
// WorkspaceStatus defines the observed state of Workspace
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func (in *Workspace) DeepCopyInto(out *Workspace) {
|
|||||||
*out = *in
|
*out = *in
|
||||||
out.TypeMeta = in.TypeMeta
|
out.TypeMeta = in.TypeMeta
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
out.Spec = in.Spec
|
in.Spec.DeepCopyInto(&out.Spec)
|
||||||
out.Status = in.Status
|
out.Status = in.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,6 +86,11 @@ func (in *WorkspaceList) DeepCopyObject() runtime.Object {
|
|||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *WorkspaceSpec) DeepCopyInto(out *WorkspaceSpec) {
|
func (in *WorkspaceSpec) DeepCopyInto(out *WorkspaceSpec) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
if in.NetworkIsolation != nil {
|
||||||
|
in, out := &in.NetworkIsolation, &out.NetworkIsolation
|
||||||
|
*out = new(bool)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceSpec.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkspaceSpec.
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ func (in *Placement) DeepCopy() *Placement {
|
|||||||
func (in *Template) DeepCopyInto(out *Template) {
|
func (in *Template) DeepCopyInto(out *Template) {
|
||||||
*out = *in
|
*out = *in
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
||||||
out.Spec = in.Spec
|
in.Spec.DeepCopyInto(&out.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Template.
|
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Template.
|
||||||
|
|||||||
@@ -384,8 +384,8 @@ func (c *NSNetworkPolicyController) addNamespace(obj interface{}) {
|
|||||||
c.nsEnqueue(ns)
|
c.nsEnqueue(ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isNetworkIsolateEnabled(ns *corev1.Namespace) bool {
|
func namespaceNetworkIsolateEnabled(ns *corev1.Namespace) bool {
|
||||||
if ns.Annotations[NamespaceNPAnnotationKey] == NamespaceNPAnnotationEnabled {
|
if ns.Annotations != nil && ns.Annotations[NamespaceNPAnnotationKey] == NamespaceNPAnnotationEnabled {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,9 +429,9 @@ func (c *NSNetworkPolicyController) syncNs(key string) error {
|
|||||||
matchWorkspace := false
|
matchWorkspace := false
|
||||||
delete := false
|
delete := false
|
||||||
nsnpList, err := c.informer.Lister().NamespaceNetworkPolicies(ns.Name).List(labels.Everything())
|
nsnpList, err := c.informer.Lister().NamespaceNetworkPolicies(ns.Name).List(labels.Everything())
|
||||||
if isNetworkIsolateEnabled(ns) {
|
if namespaceNetworkIsolateEnabled(ns) {
|
||||||
matchWorkspace = false
|
matchWorkspace = false
|
||||||
} else if wksp.Spec.NetworkIsolation {
|
} else if workspaceNetworkIsolationEnabled(wksp) {
|
||||||
matchWorkspace = true
|
matchWorkspace = true
|
||||||
} else {
|
} else {
|
||||||
delete = true
|
delete = true
|
||||||
@@ -573,6 +573,13 @@ func (c *NSNetworkPolicyController) processNSNPWorkItem() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func workspaceNetworkIsolationEnabled(wksp *workspacev1alpha1.Workspace) bool {
|
||||||
|
if wksp.Spec.NetworkIsolation != nil && *wksp.Spec.NetworkIsolation {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// NewnamespacenpController returns a controller which manages NSNSP objects.
|
// NewnamespacenpController returns a controller which manages NSNSP objects.
|
||||||
func NewNSNetworkPolicyController(
|
func NewNSNetworkPolicyController(
|
||||||
client kubernetes.Interface,
|
client kubernetes.Interface,
|
||||||
@@ -607,7 +614,7 @@ func NewNSNetworkPolicyController(
|
|||||||
UpdateFunc: func(oldObj, newObj interface{}) {
|
UpdateFunc: func(oldObj, newObj interface{}) {
|
||||||
old := oldObj.(*workspacev1alpha1.Workspace)
|
old := oldObj.(*workspacev1alpha1.Workspace)
|
||||||
new := newObj.(*workspacev1alpha1.Workspace)
|
new := newObj.(*workspacev1alpha1.Workspace)
|
||||||
if old.Spec.NetworkIsolation == new.Spec.NetworkIsolation {
|
if workspaceNetworkIsolationEnabled(old) == workspaceNetworkIsolationEnabled(new) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
controller.addWorkspace(newObj)
|
controller.addWorkspace(newObj)
|
||||||
|
|||||||
@@ -134,6 +134,25 @@ var _ = Describe("Nsnetworkpolicy", func() {
|
|||||||
go c.Start(stopCh)
|
go c.Start(stopCh)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("test func namespaceNetworkIsolateEnabled", func() {
|
||||||
|
ns := &corev1.Namespace{}
|
||||||
|
Expect(namespaceNetworkIsolateEnabled(ns)).To(BeFalse())
|
||||||
|
ns.Annotations = make(map[string]string)
|
||||||
|
Expect(namespaceNetworkIsolateEnabled(ns)).To(BeFalse())
|
||||||
|
ns.Annotations[NamespaceNPAnnotationKey] = NamespaceNPAnnotationEnabled
|
||||||
|
Expect(namespaceNetworkIsolateEnabled(ns)).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("test func workspaceNetworkIsolationEnabled", func() {
|
||||||
|
value := false
|
||||||
|
wksp := &wkspv1alpha1.Workspace{}
|
||||||
|
Expect(workspaceNetworkIsolationEnabled(wksp)).To(BeFalse())
|
||||||
|
wksp.Spec.NetworkIsolation = &value
|
||||||
|
Expect(workspaceNetworkIsolationEnabled(wksp)).To(BeFalse())
|
||||||
|
value = true
|
||||||
|
Expect(workspaceNetworkIsolationEnabled(wksp)).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
It("Should create ns networkisolate np correctly in workspace", func() {
|
It("Should create ns networkisolate np correctly in workspace", func() {
|
||||||
objSrt := fmt.Sprintf(workspaceNP, "testns", constants.WorkspaceLabelKey, "testworkspace")
|
objSrt := fmt.Sprintf(workspaceNP, "testns", constants.WorkspaceLabelKey, "testworkspace")
|
||||||
obj := &netv1.NetworkPolicy{}
|
obj := &netv1.NetworkPolicy{}
|
||||||
|
|||||||
Reference in New Issue
Block a user