Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 289: Adding SegmentStoreSvcAnnotations #296

Merged
merged 4 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/controller/pravega/pravega_segmentstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,10 @@ func MakeSegmentStoreExternalServices(pravegaCluster *api.PravegaCluster) []*cor

serviceType := getSSServiceType(pravegaCluster)
services := make([]*corev1.Service, pravegaCluster.Spec.Pravega.SegmentStoreReplicas)
var annotationMap map[string]string

for i := int32(0); i < pravegaCluster.Spec.Pravega.SegmentStoreReplicas; i++ {
annotationMap = map[string]string{}
ssPodName := util.ServiceNameForSegmentStore(pravegaCluster.Name, i)
annotationMap := pravegaCluster.Spec.Pravega.SegmentStoreServiceAnnotations
annotationValue := generateDNSAnnotationForSvc(pravegaCluster.Spec.ExternalAccess.DomainName, ssPodName)

if annotationValue != "" {
Expand Down
181 changes: 181 additions & 0 deletions pkg/controller/pravegacluster/pravegacluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,5 +714,186 @@ var _ = Describe("PravegaCluster Controller", func() {
})
})
})

Context("Custom spec with ExternalAccess with annotations and empty domain name", func() {
var (
client client.Client
err error
)

BeforeEach(func() {
annotationsMap := map[string]string{
"service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix": "abc",
}
p.Spec = v1alpha1.ClusterSpec{
Version: "0.3.2-rc2",
ExternalAccess: &v1alpha1.ExternalAccess{
Enabled: true,
Type: corev1.ServiceTypeClusterIP,
DomainName: "",
SrishT marked this conversation as resolved.
Show resolved Hide resolved
},
Pravega: &v1alpha1.PravegaSpec{
SegmentStoreReplicas: 3,
SegmentStoreExternalServiceType: corev1.ServiceTypeLoadBalancer,
SrishT marked this conversation as resolved.
Show resolved Hide resolved
SegmentStoreServiceAnnotations: annotationsMap,
},
}
p.WithDefaults()
client = fake.NewFakeClient(p)
r = &ReconcilePravegaCluster{client: client, scheme: s}
res, err = r.Reconcile(req)
})

It("shouldn't error", func() {
Ω(err).Should(BeNil())
})

Context("Pravega SegmentStore External Access", func() {
var foundSegmentStoreSvc1 *corev1.Service
var foundSegmentStoreSvc2 *corev1.Service
var foundSegmentStoreSvc3 *corev1.Service

BeforeEach(func() {
foundSegmentStoreSvc1 = &corev1.Service{}
nn1 := types.NamespacedName{
Name: util.ServiceNameForSegmentStore(p.Name, 0),
Namespace: Namespace,
}
err = client.Get(context.TODO(), nn1, foundSegmentStoreSvc1)

foundSegmentStoreSvc2 = &corev1.Service{}
nn2 := types.NamespacedName{
Name: util.ServiceNameForSegmentStore(p.Name, 1),
Namespace: Namespace,
}
err = client.Get(context.TODO(), nn2, foundSegmentStoreSvc2)

foundSegmentStoreSvc3 = &corev1.Service{}
nn3 := types.NamespacedName{
Name: util.ServiceNameForSegmentStore(p.Name, 2),
Namespace: Namespace,
}
err = client.Get(context.TODO(), nn3, foundSegmentStoreSvc3)

})

It("should create all segmentstore services", func() {
Ω(err).Should(BeNil())
})

It("should set external access service type to LoadBalancer for each service", func() {
SrishT marked this conversation as resolved.
Show resolved Hide resolved
Ω(p.Spec.Pravega.SegmentStoreExternalServiceType).Should(Equal(corev1.ServiceTypeLoadBalancer))
Ω(p.Spec.ExternalAccess.Type).Should(Equal(corev1.ServiceTypeClusterIP))
Ω(foundSegmentStoreSvc1.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
SrishT marked this conversation as resolved.
Show resolved Hide resolved
Ω(foundSegmentStoreSvc2.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
Ω(foundSegmentStoreSvc3.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
})

It("should set provided annotations", func() {
mapLength := len(foundSegmentStoreSvc1.GetAnnotations())
Ω(mapLength).To(Equal(1))
Expect(foundSegmentStoreSvc1.GetAnnotations()).To(HaveKeyWithValue(
"service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix",
"abc"))
Expect(foundSegmentStoreSvc2.GetAnnotations()).To(HaveKeyWithValue(
"service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix",
"abc"))
Expect(foundSegmentStoreSvc3.GetAnnotations()).To(HaveKeyWithValue(
"service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix",
"abc"))
})
})
})

Context("Custom spec with ExternalAccess with domain name and without other annotations", func() {
var (
client client.Client
err error
domainName string
)

BeforeEach(func() {
domainName = "pravega.com."
p.Spec = v1alpha1.ClusterSpec{
Version: "0.3.2-rc2",
ExternalAccess: &v1alpha1.ExternalAccess{
Enabled: true,
Type: corev1.ServiceTypeClusterIP,
DomainName: domainName,
},
Pravega: &v1alpha1.PravegaSpec{
SegmentStoreReplicas: 3,
SegmentStoreExternalServiceType: corev1.ServiceTypeLoadBalancer,
SrishT marked this conversation as resolved.
Show resolved Hide resolved
},
}
p.WithDefaults()
client = fake.NewFakeClient(p)
r = &ReconcilePravegaCluster{client: client, scheme: s}
res, err = r.Reconcile(req)
})

It("shouldn't error", func() {
Ω(err).Should(BeNil())
})

Context("Pravega SegmentStore External Access", func() {
var foundSegmentStoreSvc1 *corev1.Service
var foundSegmentStoreSvc2 *corev1.Service
var foundSegmentStoreSvc3 *corev1.Service

BeforeEach(func() {
foundSegmentStoreSvc1 = &corev1.Service{}
nn1 := types.NamespacedName{
Name: util.ServiceNameForSegmentStore(p.Name, 0),
Namespace: Namespace,
}
err = client.Get(context.TODO(), nn1, foundSegmentStoreSvc1)

foundSegmentStoreSvc2 = &corev1.Service{}
nn2 := types.NamespacedName{
Name: util.ServiceNameForSegmentStore(p.Name, 1),
Namespace: Namespace,
}
err = client.Get(context.TODO(), nn2, foundSegmentStoreSvc2)

foundSegmentStoreSvc3 = &corev1.Service{}
nn3 := types.NamespacedName{
Name: util.ServiceNameForSegmentStore(p.Name, 2),
Namespace: Namespace,
}
err = client.Get(context.TODO(), nn3, foundSegmentStoreSvc3)

})

It("should create all segmentstore services", func() {
Ω(err).Should(BeNil())
})

It("should set external access service type to LoadBalancer for each service", func() {
Ω(p.Spec.Pravega.SegmentStoreExternalServiceType).Should(Equal(corev1.ServiceTypeLoadBalancer))
SrishT marked this conversation as resolved.
Show resolved Hide resolved
Ω(p.Spec.ExternalAccess.Type).Should(Equal(corev1.ServiceTypeClusterIP))
Ω(foundSegmentStoreSvc1.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
SrishT marked this conversation as resolved.
Show resolved Hide resolved
Ω(foundSegmentStoreSvc2.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
Ω(foundSegmentStoreSvc3.Spec.Type).Should(Equal(corev1.ServiceTypeLoadBalancer))
})

It("should set provided domain name as annotation", func() {
mapLength := len(foundSegmentStoreSvc1.GetAnnotations())
Ω(mapLength).To(Equal(1))
svcName1 := util.ServiceNameForSegmentStore(p.Name, 0) + "." + domainName
Expect(foundSegmentStoreSvc1.GetAnnotations()).To(HaveKeyWithValue(
"external-dns.alpha.kubernetes.io/hostname", svcName1))

svcName2 := util.ServiceNameForSegmentStore(p.Name, 1) + "." + domainName
Expect(foundSegmentStoreSvc2.GetAnnotations()).To(HaveKeyWithValue(
"external-dns.alpha.kubernetes.io/hostname", svcName2))

svcName3 := util.ServiceNameForSegmentStore(p.Name, 2) + "." + domainName
Expect(foundSegmentStoreSvc3.GetAnnotations()).To(HaveKeyWithValue(
"external-dns.alpha.kubernetes.io/hostname", svcName3))
})
})
})

})
})