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

Test that new single replica topology API is taken into account #25812

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/extended/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
_ "github.com/openshift/origin/test/extended/quota"
_ "github.com/openshift/origin/test/extended/router"
_ "github.com/openshift/origin/test/extended/security"
_ "github.com/openshift/origin/test/extended/single_node"
_ "github.com/openshift/origin/test/extended/tbr_health"
_ "github.com/openshift/origin/test/extended/templates"
_ "github.com/openshift/origin/test/extended/topology_manager"
Expand Down
148 changes: 148 additions & 0 deletions test/extended/single_node/topology.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package single_node

import (
"context"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
v1 "github.com/openshift/api/config/v1"
exutil "github.com/openshift/origin/test/extended/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
e2e "k8s.io/kubernetes/test/e2e/framework"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
"strings"
)

func getOpenshiftNamespaces(f *e2e.Framework) []corev1.Namespace {
list, err := f.ClientSet.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())

var openshiftNamespaces []corev1.Namespace
for _, namespace := range list.Items {
if strings.HasPrefix(namespace.Name, "openshift-") {
openshiftNamespaces = append(openshiftNamespaces, namespace)
}
}

return openshiftNamespaces
}

func getNamespaceDeployments(f *e2e.Framework, namespace corev1.Namespace) []appsv1.Deployment {
list, err := f.ClientSet.AppsV1().Deployments(namespace.Name).List(context.Background(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return list.Items

You're not doing any filtering here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, no filtering. The loop looks ridiculous because it's leftover after some modifications I did that made it obsolete. Will fix. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0debdeb

return list.Items
}

func getTopologies(f *e2e.Framework) (controlPlaneTopology, infraTopology v1.TopologyMode) {
oc := exutil.NewCLIWithFramework(f)
infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(),
"cluster", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

return infra.Status.ControlPlaneTopology, infra.Status.InfrastructureTopology
}

func isInfrastructureDeployment(deployment appsv1.Deployment) bool {
infrastructureNamespaces := map[string][]string{
"openshift-ingress": {
"router-default",
},
}

namespaceInfraDeployments, ok := infrastructureNamespaces[deployment.Namespace]

if !ok {
return false
}

for _, infraDeploymentName := range namespaceInfraDeployments {
if deployment.Name == infraDeploymentName {
return true
}
}

return false
}

func validateReplicas(deployment appsv1.Deployment,
controlPlaneTopology, infraTopology v1.TopologyMode, failureAllowed bool) {
if isInfrastructureDeployment(deployment) {
if infraTopology != v1.SingleReplicaTopologyMode {
return
}
} else if controlPlaneTopology != v1.SingleReplicaTopologyMode {
return
}

Expect(deployment.Spec.Replicas).ToNot(BeNil())

replicas := int(*deployment.Spec.Replicas)

if !failureAllowed {
Expect(replicas).To(Equal(1),
"%s in %s namespace has wrong number of replicas", deployment.Name, deployment.Namespace)
} else {
if replicas == 1 {
t := GinkgoT()
t.Logf("Deployment %s in namespace %s has one replica, consider taking it off the topology allow-list",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who are we really expecting will react to this message?

Copy link
Contributor Author

@omertuc omertuc Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intended mostly for me. We slowly want to remove operators from that list until it's empty, and it'll be helpful for me to see that message in the logs. It'll be removed once we finally get rid of this list

deployment.Name, deployment.Namespace)
}
}
}

func isAllowedToFail(deployment appsv1.Deployment) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment explaining these special cases would be useful for future reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will add one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 395d469

// allowedToFail is a list of deployments that currently have 2 replicas even in single-replica
// topology deployments, because their operator has yet to be made aware of the new API.
// We will slowly remove deployments from this list once their operators have been made
// aware until this list is empty and this function will be removed.
allowedToFail := map[string][]string{
"openshift-authentication": {
"oauth-openshift",
},
"openshift-console": {
"console",
"downloads",
},
"openshift-monitoring": {
"prometheus-adapter",
"thanos-querier",
},
"openshift-operator-lifecycle-manager": {
"packageserver",
},
}

namespaceAllowedToFailDeployments, ok := allowedToFail[deployment.Namespace]

if !ok {
return false
}

for _, allowedToFailDeploymentName := range namespaceAllowedToFailDeployments {
if deployment.Name == allowedToFailDeploymentName {
return true
}
}

return false
}

var _ = Describe("[sig-arch] Cluster topology single node tests", func() {
f := e2e.NewDefaultFramework("single-node")

It("Verify that OpenShift components deploy one replica in SingleReplica topology mode", func() {
controlPlaneTopology, infraTopology := getTopologies(f)

if controlPlaneTopology != v1.SingleReplicaTopologyMode && infraTopology != v1.SingleReplicaTopologyMode {
e2eskipper.Skipf("Test is only relevant for single replica topologies")
}

for _, namespace := range getOpenshiftNamespaces(f) {
for _, deployment := range getNamespaceDeployments(f, namespace) {
validateReplicas(deployment, controlPlaneTopology, infraTopology, isAllowedToFail(deployment))
}
}
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.