Skip to content

Commit

Permalink
add unit test for createLBStatus
Browse files Browse the repository at this point in the history
Signed-off-by: sakshi-1505 <sakshipatle.0808cs171134@gmail.com>
  • Loading branch information
sakshi-1505 committed Oct 15, 2023
1 parent 5e2668a commit 2da2817
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 4 deletions.
2 changes: 1 addition & 1 deletion charts/cinder-csi-plugin/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
appVersion: v1.28.0
description: Cinder CSI Chart for OpenStack
name: openstack-cinder-csi
version: 2.29.0-alpha.1
version: 2.29.0-alpha.2
home: https://github.com/kubernetes/cloud-provider-openstack
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
maintainers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ spec:
affinity: {{ toYaml .Values.csi.plugin.controllerPlugin.affinity | nindent 8 }}
nodeSelector: {{ toYaml .Values.csi.plugin.controllerPlugin.nodeSelector | nindent 8 }}
tolerations: {{ toYaml .Values.csi.plugin.controllerPlugin.tolerations | nindent 8 }}
{{- with .Values.csi.plugin.controllerPlugin.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
Expand Down
4 changes: 4 additions & 0 deletions charts/cinder-csi-plugin/templates/nodeplugin-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ spec:
affinity: {{ toYaml .Values.csi.plugin.nodePlugin.affinity | nindent 8 }}
nodeSelector: {{ toYaml .Values.csi.plugin.nodePlugin.nodeSelector | nindent 8 }}
tolerations: {{ toYaml .Values.csi.plugin.nodePlugin.tolerations | nindent 8 }}
{{- with .Values.csi.plugin.nodePlugin.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
Expand Down
10 changes: 10 additions & 0 deletions charts/cinder-csi-plugin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ csi:
tolerations:
- operator: Exists
kubeletDir: /var/lib/kubelet
# Allow for specifying internal IP addresses for multiple hostnames
# hostAliases:
# - ip: "10.0.0.1"
# hostnames:
# - "keystone.hostname.com"
controllerPlugin:
replicas: 1
strategy:
Expand Down Expand Up @@ -110,6 +115,11 @@ csi:
affinity: {}
nodeSelector: {}
tolerations: []
# Allow for specifying internal IP addresses for multiple hostnames
# hostAliases:
# - ip: "10.0.0.1"
# hostnames:
# - "keystone.hostname.com"
resources: {}
# Enable built-in http server through the http-endpoint flag
httpEndpoint:
Expand Down
2 changes: 1 addition & 1 deletion charts/manila-csi-plugin/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
appVersion: v1.28.0
description: Manila CSI Chart for OpenStack
name: openstack-manila-csi
version: 2.29.0-alpha.0
version: 2.29.0-alpha.1
home: http://github.com/kubernetes/cloud-provider-openstack
icon: https://github.com/kubernetes/kubernetes/blob/master/logo/logo.png
maintainers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ spec:
{{- if .Values.controllerplugin.tolerations }}
tolerations: {{ toYaml .Values.controllerplugin.tolerations | nindent 8 }}
{{- end }}
{{- with .Values.controllerplugin.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml .Values.imagePullSecrets | nindent 8 }}
Expand Down
4 changes: 4 additions & 0 deletions charts/manila-csi-plugin/templates/nodeplugin-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ spec:
{{- if .Values.nodeplugin.tolerations }}
tolerations: {{ toYaml .Values.nodeplugin.tolerations | nindent 8 }}
{{- end }}
{{- with .Values.nodeplugin.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.nodeplugin.priorityClassName }}
priorityClassName: {{ .Values.nodeplugin.priorityClassName }}
{{- end }}
Expand Down
10 changes: 10 additions & 0 deletions charts/manila-csi-plugin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ nodeplugin:
nodeSelector: {}
tolerations: []
affinity: {}
# Allow for specifying internal IP addresses for multiple hostnames
# hostAliases:
# - ip: "10.0.0.1"
# hostnames:
# - "keystone.hostname.com"
priorityClassName: ""
# Use fullnameOverride to fully override the name of this component
# fullnameOverride: some-other-name
Expand Down Expand Up @@ -102,6 +107,11 @@ controllerplugin:
nodeSelector: {}
tolerations: []
affinity: {}
# Allow for specifying internal IP addresses for multiple hostnames
# hostAliases:
# - ip: "10.0.0.1"
# hostnames:
# - "keystone.hostname.com"
# Use fullnameOverride to fully override the name of this component
# fullnameOverride: some-other-name

Expand Down
2 changes: 1 addition & 1 deletion charts/openstack-cloud-controller-manager/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Openstack Cloud Controller Manager Helm Chart
icon: https://object-storage-ca-ymq-1.vexxhost.net/swift/v1/6e4619c416ff4bd19e1c087f27a43eea/www-images-prod/openstack-logo/OpenStack-Logo-Vertical.png
home: https://github.com/kubernetes/cloud-provider-openstack
name: openstack-cloud-controller-manager
version: 2.29.0-alpha.2
version: 2.29.0-alpha.3
maintainers:
- name: eumel8
email: f.kloeker@telekom.de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ .Values.serviceAccountName }}
containers:
- name: openstack-cloud-controller-manager
Expand Down
6 changes: 6 additions & 0 deletions charts/openstack-cloud-controller-manager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ cloudConfig:
blockStorage:
metadata:

# Allow for specifying internal IP addresses for multiple hostnames
# hostAliases:
# - ip: "10.0.0.1"
# hostnames:
# - "keystone.hostname.com"

## Pod priority settings
## ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/
priorityClassName:
Expand Down
172 changes: 172 additions & 0 deletions pkg/openstack/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type testPopListener struct {
Expand Down Expand Up @@ -534,3 +535,174 @@ func Test_getListenerProtocol(t *testing.T) {
})
}
}

func TestLbaasV2_createLoadBalancerStatus(t *testing.T) {
type fields struct {
LoadBalancer LoadBalancer
}
type args struct {
service *corev1.Service
svcConf *serviceConfig
addr string
}
tests := []struct {
name string
fields fields
args args
want *corev1.LoadBalancerStatus
}{
{
name: "it should return hostname from service annotation",
fields: fields{
LoadBalancer: LoadBalancer{
opts: LoadBalancerOpts{
EnableIngressHostname: false,
IngressHostnameSuffix: "test",
},
},
},
args: args{
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"loadbalancer.openstack.org/hostname": "testHostName"},
},
},
svcConf: &serviceConfig{
enableProxyProtocol: false,
},
addr: "10.10.0.6",
},
want: &corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{
{
Hostname: "testHostName",
},
},
},
},
{
name: "it should return fakehostname if proxyProtocal & IngressHostName is enabled without svc annotation",
fields: fields{
LoadBalancer: LoadBalancer{
opts: LoadBalancerOpts{
EnableIngressHostname: true,
IngressHostnameSuffix: "ingress-suffix",
},
},
},
args: args{
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"test": "key"},
},
},
svcConf: &serviceConfig{
enableProxyProtocol: true,
},
addr: "10.10.0.6",
},
want: &corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{
{
Hostname: "10.10.0.6.ingress-suffix",
},
},
},
},
{
name: "it should default to ip address if not hostname can be found from svc or proxyProtocol",
fields: fields{
LoadBalancer: LoadBalancer{
opts: LoadBalancerOpts{
EnableIngressHostname: false,
IngressHostnameSuffix: "ingress-suffix",
},
},
},
args: args{
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"test": "key"},
},
},
svcConf: &serviceConfig{
enableProxyProtocol: false,
},
addr: "10.10.0.6",
},
want: &corev1.LoadBalancerStatus{
Ingress: []corev1.LoadBalancerIngress{
{
IP: "10.10.0.6",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lbaas := &LbaasV2{
LoadBalancer: tt.fields.LoadBalancer,
}
assert.Equal(t, tt.want, lbaas.createLoadBalancerStatus(tt.args.service, tt.args.svcConf, tt.args.addr))
})
}
}

func Test_getIntFromServiceAnnotation(t *testing.T) {
type args struct {
service *corev1.Service
annotationKey string
defaultSetting int
}
tests := []struct {
name string
args args
want int
}{
{
name: "return default setting if no service annotation",
args: args{
defaultSetting: 1,
annotationKey: "bar",
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"foo": "2"},
},
},
},
want: 1,
},
{
name: "return annotation key if it exists in service annotation",
args: args{
defaultSetting: 1,
annotationKey: "foo",
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"foo": "2"},
},
},
},
want: 2,
},
{
name: "return default setting if key isn't valid integer",
args: args{
defaultSetting: 1,
annotationKey: "foo",
service: &corev1.Service{
ObjectMeta: v1.ObjectMeta{
Annotations: map[string]string{"foo": "bar"},
},
},
},
want: 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, getIntFromServiceAnnotation(tt.args.service, tt.args.annotationKey, tt.args.defaultSetting))
})
}
}
3 changes: 2 additions & 1 deletion tests/ci-occm-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ cleanup() {
}
trap cleanup EXIT

python3 -m pip install requests ansible
apt-get update
apt-get install -y python3-requests ansible

# If BOSKOS_HOST is set then acquire a resource of type ${RESOURCE_TYPE} from Boskos.
if [ -n "${BOSKOS_HOST:-}" ]; then
Expand Down

0 comments on commit 2da2817

Please sign in to comment.