-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: block use of NodePort Services
- Loading branch information
1 parent
5bca3b7
commit e6da507
Showing
4 changed files
with
191 additions
and
0 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,88 @@ | ||
//+build e2e | ||
|
||
/* | ||
Copyright 2020 Clastix Labs. | ||
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 e2e | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
|
||
"github.com/clastix/capsule/api/v1alpha1" | ||
) | ||
|
||
var _ = Describe("creating a nodePort service when it is disabled for Tenant", func() { | ||
tnt := &v1alpha1.Tenant{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "disable-node-ports", | ||
Annotations: map[string]string{ | ||
"capsule.clastix.io/enable-node-ports": "false", | ||
}, | ||
}, | ||
Spec: v1alpha1.TenantSpec{ | ||
Owner: v1alpha1.OwnerSpec{ | ||
Name: "google", | ||
Kind: "User", | ||
}, | ||
}, | ||
} | ||
|
||
JustBeforeEach(func() { | ||
EventuallyCreation(func() error { | ||
tnt.ResourceVersion = "" | ||
return k8sClient.Create(context.TODO(), tnt) | ||
}).Should(Succeed()) | ||
}) | ||
JustAfterEach(func() { | ||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed()) | ||
}) | ||
|
||
It("should fail creating a service with NodePort type", func() { | ||
ns := NewNamespace("disable-node-ports") | ||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) | ||
|
||
svc := &corev1.Service{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "disable-node-ports", | ||
Namespace: ns.GetName(), | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeNodePort, | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
Port: 9999, | ||
TargetPort: intstr.IntOrString{ | ||
Type: intstr.Int, | ||
IntVal: 9999, | ||
}, | ||
Protocol: corev1.ProtocolTCP, | ||
}, | ||
}, | ||
}, | ||
} | ||
EventuallyCreation(func() error { | ||
cs := ownerClient(tnt) | ||
_, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) | ||
return err | ||
}).ShouldNot(Succeed()) | ||
}) | ||
}) |
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,85 @@ | ||
//+build e2e | ||
|
||
/* | ||
Copyright 2020 Clastix Labs. | ||
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 e2e | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
|
||
"github.com/clastix/capsule/api/v1alpha1" | ||
) | ||
|
||
var _ = Describe("creating a nodePort service when it is enabled for Tenant", func() { | ||
tnt := &v1alpha1.Tenant{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "enable-node-ports", | ||
}, | ||
Spec: v1alpha1.TenantSpec{ | ||
Owner: v1alpha1.OwnerSpec{ | ||
Name: "google", | ||
Kind: "User", | ||
}, | ||
}, | ||
} | ||
|
||
JustBeforeEach(func() { | ||
EventuallyCreation(func() error { | ||
tnt.ResourceVersion = "" | ||
return k8sClient.Create(context.TODO(), tnt) | ||
}).Should(Succeed()) | ||
}) | ||
JustAfterEach(func() { | ||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed()) | ||
}) | ||
|
||
It("should allow creating a service with NodePort type", func() { | ||
ns := NewNamespace("enable-node-ports") | ||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed()) | ||
|
||
svc := &corev1.Service{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "enable-node-ports", | ||
Namespace: ns.GetName(), | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeNodePort, | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
Port: 9999, | ||
TargetPort: intstr.IntOrString{ | ||
Type: intstr.Int, | ||
IntVal: 9999, | ||
}, | ||
Protocol: corev1.ProtocolTCP, | ||
}, | ||
}, | ||
}, | ||
} | ||
EventuallyCreation(func() error { | ||
cs := ownerClient(tnt) | ||
_, err := cs.CoreV1().Services(ns.Name).Create(context.Background(), svc, metav1.CreateOptions{}) | ||
return err | ||
}).Should(Succeed()) | ||
}) | ||
}) |
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