Skip to content

Commit

Permalink
WIP - panic when downscale + functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
averdagu committed Nov 24, 2023
1 parent 7005acc commit f7ce6d7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
30 changes: 27 additions & 3 deletions controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/go-logr/logr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -589,12 +590,25 @@ func (r *OVNDBClusterReconciler) reconcileServices(
if err != nil {
return ctrl.Result{}, err
}
// Delete DNS thingy
dnsRecord := &infranetworkv1.DNSData{}
dnsName := "dns-" + serviceName + fmt.Sprintf("-%d", i)
dnsNamespace := helper.GetBeforeObject().GetNamespace()
Log.Info(fmt.Sprintf("Name: %v, Namespace: %v", dnsName, dnsNamespace))
test_err := helper.GetClient().Get(ctx, types.NamespacedName{Name: dnsName, Namespace: dnsNamespace}, dnsRecord)
if test_err != nil {
Log.Info(fmt.Sprintf("Error: %v", test_err))
}
err := helper.GetClient().Delete(ctx, dnsRecord)
if err != nil {
Log.Info(fmt.Sprintf("Error: %v", err))
}

}
}

Log.Info("DNS Starts here")
Log.Info(fmt.Sprintf("AAA - Using instance: %v", instance))
Log.Info(fmt.Sprintf("AAA - Using instance.spec: %v", instance.Spec))

serviceName = ovndbcluster.ServiceNameSB
if instance.Spec.DBType == v1beta1.NBDBType {
serviceName = ovndbcluster.ServiceNameNB
Expand All @@ -606,7 +620,14 @@ func (r *OVNDBClusterReconciler) reconcileServices(
if err != nil {
return ctrl.Result{}, err
}
for _, ovnPod := range podList.Items {
if len(podList.Items) > int(*(instance.Spec.Replicas)) {

}
for i, ovnPod := range podList.Items {
if i >= int(*(instance.Spec.Replicas)) {
Log.Info(fmt.Sprintf("In iteration %v is OOO, exit", i))
break
}
Log.Info(fmt.Sprintf("Using Pod: %v", ovnPod.Name))
var dnsName string
var dnsIP string
Expand All @@ -619,6 +640,9 @@ func (r *OVNDBClusterReconciler) reconcileServices(
ovnPod.Name,
ovnPod.Namespace,
)
if err != nil {
return ctrl.Result{}, err
}
hostname := svc.ObjectMeta.Annotations[infranetworkv1.AnnotationHostnameKey]
hostnames = append(hostnames, hostname)

Expand Down
12 changes: 12 additions & 0 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"time"

"github.com/google/uuid"
"github.com/onsi/gomega"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
Expand Down Expand Up @@ -258,3 +260,13 @@ func SimulateDaemonsetNumberReadyWithPods(name types.NamespacedName, networkIPs

logger.Info("Simulated daemonset success", "on", name)
}

// DNSData
func GetDNSData(name types.NamespacedName) *infranetworkv1.DNSData {
dns := &infranetworkv1.DNSData{}
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, name, dns)).Should(gomega.Succeed())
}).Should(gomega.Succeed())

return dns
}
8 changes: 5 additions & 3 deletions tests/functional/ovncontroller_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ var _ = Describe("OVNController controller", func() {
daemonSetName,
map[string][]string{namespace + "/internalapi": {"10.0.0.1"}},
)
ExpectedExternalSBEndpoint := "tcp:ovsdbserver-sb." + namespace + ".svc:6642"
externalSBEndpoint := "10.0.0.254"
SetExternalEndpoint(dbs[1], externalSBEndpoint)

Expand All @@ -377,7 +378,7 @@ var _ = Describe("OVNController controller", func() {
}, timeout, interval).ShouldNot(BeNil())

Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should(
ContainSubstring("ovn-remote: %s", externalSBEndpoint))
ContainSubstring("ovn-remote: %s", ExpectedExternalSBEndpoint))
Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should(
ContainSubstring("ovn-encap-type: %s", "geneve"))
})
Expand Down Expand Up @@ -460,21 +461,22 @@ var _ = Describe("OVNController controller", func() {
map[string][]string{namespace + "/internalapi": {"10.0.0.1"}},
)
externalSBEndpoint := "10.0.0.254"
ExpectedExternalSBEndpoint := "tcp:ovsdbserver-sb." + namespace + ".svc:6642"
SetExternalEndpoint(dbs[1], externalSBEndpoint)

Eventually(func() corev1.ConfigMap {
return *th.GetConfigMap(externalCM)
}, timeout, interval).ShouldNot(BeNil())

Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should(
ContainSubstring("ovn-remote: %s", externalSBEndpoint))
ContainSubstring("ovn-remote: %s", ExpectedExternalSBEndpoint))

newExternalSBEndpoint := "10.0.0.250"
SetExternalEndpoint(dbs[1], newExternalSBEndpoint)

Eventually(func(g Gomega) {
g.Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should(
ContainSubstring("ovn-remote: %s", newExternalSBEndpoint))
ContainSubstring("ovn-remote: %s", ExpectedExternalSBEndpoint))
}, timeout, interval).Should(Succeed())
})
})
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/ovndbcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
"github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
Expand Down Expand Up @@ -73,6 +74,19 @@ var _ = Describe("OVNDBCluster controller", func() {
Entry("config-data CM", "config-data"),
Entry("scripts CM", "scripts"),
)
DescribeTable("should not create the dnsdata CR",
func(DnsName string) {
Eventually(func() *infranetworkv1.DNSData {
dnsm := types.NamespacedName{
Namespace: OVNDBClusterName.Namespace,
Name: fmt.Sprintf("dns-%s", OVNDBClusterName.Name),
}
return GetDNSData(dnsm)
}, timeout, interval).Should(BeNil())
},
Entry("config-data CM", "config-data"),
Entry("scripts CM", "scripts"),
)
DescribeTable("should eventually create the config maps",
func(cmName string) {
Eventually(func() corev1.ConfigMap {
Expand Down

0 comments on commit f7ce6d7

Please sign in to comment.