Skip to content

Commit

Permalink
Name function to derivate consolelink name, and use it on tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Aug 3, 2020
1 parent 04e2ac5 commit 8c1704f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 28 deletions.
7 changes: 6 additions & 1 deletion pkg/consolelink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
// RouteAnnotation used to annotate the link with the route name
var RouteAnnotation = "consolelink.jaegertracing.io/route"

//Name derived a console link resource name from jaeger instance
func Name(jaeger *v1.Jaeger) string {
return "jaeger-" + jaeger.Namespace + "-" + jaeger.Name
}

// Get returns a ConsoleLink specification for the current instance
func Get(jaeger *v1.Jaeger, route *routev1.Route) *consolev1.ConsoleLink {
// If ingress is not enable there is no reason for create a console link
Expand All @@ -22,7 +27,7 @@ func Get(jaeger *v1.Jaeger, route *routev1.Route) *consolev1.ConsoleLink {

return &consolev1.ConsoleLink{
ObjectMeta: metav1.ObjectMeta{
Name: "jaeger-" + jaeger.Namespace + "-" + jaeger.Name,
Name: Name(jaeger),
Namespace: jaeger.Namespace, // Prevent warning at creation time.
Labels: map[string]string{
"app.kubernetes.io/instance": jaeger.Name,
Expand Down
5 changes: 3 additions & 2 deletions pkg/consolelink/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package consolelink

import (
"fmt"
"testing"

consolev1 "github.com/openshift/api/console/v1"
Expand Down Expand Up @@ -29,7 +30,7 @@ func TestConsoleLinkGet(t *testing.T) {
}

link := Get(jaeger, route)
assert.Equal(t, "jaeger-"+jaeger.Namespace+"-"+jaeger.Name, link.Name)
assert.Equal(t, Name(jaeger), link.Name)
assert.Contains(t, link.Annotations, RouteAnnotation)
assert.Equal(t, routerName, link.Annotations[RouteAnnotation])
}
Expand All @@ -53,6 +54,6 @@ func TestUpdateHref(t *testing.T) {
assert.Equal(t, link.Spec.Href, "")
route.Spec.Host = "namespace.somehostname"
newLinks := UpdateHref([]corev1.Route{route}, []consolev1.ConsoleLink{*link})
assert.Equal(t, "https://"+route.Spec.Host, newLinks[0].Spec.Href)
assert.Equal(t, fmt.Sprintf("https://%s", route.Spec.Host), newLinks[0].Spec.Href)

}
2 changes: 1 addition & 1 deletion pkg/controller/jaeger/consolelink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestConsoleLinksCreateExistingNameInAnotherNamespace(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: nsn.Name,
Namespace: nsn.Namespace,
// Same route name and anotation
// Same route name and annotation
Annotations: map[string]string{
consolelink.RouteAnnotation: "my-route-1",
},
Expand Down
21 changes: 12 additions & 9 deletions pkg/strategy/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"strings"
"testing"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/consolelink"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/types"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/storage"
"github.com/jaegertracing/jaeger-operator/pkg/util"
)
Expand All @@ -21,8 +23,9 @@ func init() {

func TestCreateAllInOneDeployment(t *testing.T) {
name := "TestCreateAllInOneDeployment"
c := newAllInOneStrategy(context.Background(), v1.NewJaeger(types.NamespacedName{Name: name}))
assertDeploymentsAndServicesForAllInOne(t, name, c, false, false, false)
jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
c := newAllInOneStrategy(context.Background(), jaeger)
assertDeploymentsAndServicesForAllInOne(t, jaeger, c, false, false, false)
}

func TestCreateAllInOneDeploymentOnOpenShift(t *testing.T) {
Expand All @@ -34,7 +37,7 @@ func TestCreateAllInOneDeploymentOnOpenShift(t *testing.T) {
normalize(context.Background(), jaeger)

c := newAllInOneStrategy(context.Background(), jaeger)
assertDeploymentsAndServicesForAllInOne(t, name, c, false, true, false)
assertDeploymentsAndServicesForAllInOne(t, jaeger, c, false, true, false)
}

func TestCreateAllInOneDeploymentWithDaemonSetAgent(t *testing.T) {
Expand All @@ -44,7 +47,7 @@ func TestCreateAllInOneDeploymentWithDaemonSetAgent(t *testing.T) {
j.Spec.Agent.Strategy = "DaemonSet"

c := newAllInOneStrategy(context.Background(), j)
assertDeploymentsAndServicesForAllInOne(t, name, c, true, false, false)
assertDeploymentsAndServicesForAllInOne(t, j, c, true, false, false)
}

func TestCreateAllInOneDeploymentWithUIConfigMap(t *testing.T) {
Expand All @@ -58,7 +61,7 @@ func TestCreateAllInOneDeploymentWithUIConfigMap(t *testing.T) {
})

c := newAllInOneStrategy(context.Background(), j)
assertDeploymentsAndServicesForAllInOne(t, name, c, false, false, true)
assertDeploymentsAndServicesForAllInOne(t, j, c, false, false, true)
}

func TestDelegateAllInOneDependencies(t *testing.T) {
Expand All @@ -74,9 +77,9 @@ func TestNoAutoscaleForAllInOne(t *testing.T) {
assert.Len(t, c.HorizontalPodAutoscalers(), 0)
}

func assertDeploymentsAndServicesForAllInOne(t *testing.T, name string, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) {
func assertDeploymentsAndServicesForAllInOne(t *testing.T, instance *v1.Jaeger, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) {
// TODO(jpkroehling): this func deserves a refactoring already

name := instance.Name
expectedNumObjs := 7

if hasDaemonSet {
Expand Down Expand Up @@ -113,7 +116,7 @@ func assertDeploymentsAndServicesForAllInOne(t *testing.T, name string, s S, has
consoleLinks := map[string]bool{}
if viper.GetString("platform") == v1.FlagPlatformOpenShift {
routes[fmt.Sprintf("%s", util.DNSName(name))] = false
consoleLinks["jaeger--"+name] = false
consoleLinks[consolelink.Name(instance)] = false

} else {
ingresses[fmt.Sprintf("%s-query", name)] = false
Expand Down
18 changes: 11 additions & 7 deletions pkg/strategy/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"testing"

"github.com/jaegertracing/jaeger-operator/pkg/consolelink"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
Expand All @@ -23,8 +25,9 @@ func init() {

func TestCreateProductionDeployment(t *testing.T) {
name := "TestCreateProductionDeployment"
c := newProductionStrategy(context.Background(), v1.NewJaeger(types.NamespacedName{Name: name}))
assertDeploymentsAndServicesForProduction(t, name, c, false, false, false)
jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
c := newProductionStrategy(context.Background(), jaeger)
assertDeploymentsAndServicesForProduction(t, jaeger, c, false, false, false)
}

func TestCreateProductionDeploymentOnOpenShift(t *testing.T) {
Expand All @@ -36,7 +39,7 @@ func TestCreateProductionDeploymentOnOpenShift(t *testing.T) {
normalize(context.Background(), jaeger)

c := newProductionStrategy(context.Background(), jaeger)
assertDeploymentsAndServicesForProduction(t, name, c, false, true, false)
assertDeploymentsAndServicesForProduction(t, jaeger, c, false, true, false)
}

func TestCreateProductionDeploymentWithDaemonSetAgent(t *testing.T) {
Expand All @@ -46,7 +49,7 @@ func TestCreateProductionDeploymentWithDaemonSetAgent(t *testing.T) {
j.Spec.Agent.Strategy = "DaemonSet"

c := newProductionStrategy(context.Background(), j)
assertDeploymentsAndServicesForProduction(t, name, c, true, false, false)
assertDeploymentsAndServicesForProduction(t, j, c, true, false, false)
}

func TestCreateProductionDeploymentWithUIConfigMap(t *testing.T) {
Expand All @@ -60,7 +63,7 @@ func TestCreateProductionDeploymentWithUIConfigMap(t *testing.T) {
})

c := newProductionStrategy(context.Background(), j)
assertDeploymentsAndServicesForProduction(t, name, c, false, false, true)
assertDeploymentsAndServicesForProduction(t, j, c, false, false, true)
}

func TestOptionsArePassed(t *testing.T) {
Expand Down Expand Up @@ -120,7 +123,8 @@ func TestAutoscaleForProduction(t *testing.T) {
assert.Len(t, c.HorizontalPodAutoscalers(), 1)
}

func assertDeploymentsAndServicesForProduction(t *testing.T, name string, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) {
func assertDeploymentsAndServicesForProduction(t *testing.T, instance *v1.Jaeger, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) {
name := instance.Name
expectedNumObjs := 7

if hasDaemonSet {
Expand Down Expand Up @@ -154,7 +158,7 @@ func assertDeploymentsAndServicesForProduction(t *testing.T, name string, s S, h
consoleLinks := map[string]bool{}
if viper.GetString("platform") == v1.FlagPlatformOpenShift {
routes[util.DNSName(name)] = false
consoleLinks["jaeger--"+name] = false
consoleLinks[consolelink.Name(instance)] = false
} else {
ingresses[fmt.Sprintf("%s-query", name)] = false
}
Expand Down
19 changes: 11 additions & 8 deletions pkg/strategy/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"testing"

"github.com/jaegertracing/jaeger-operator/pkg/consolelink"

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
Expand All @@ -18,13 +20,13 @@ import (

func init() {
viper.SetDefault("jaeger-agent-image", "jaegertracing/jaeger-agent")

}

func TestCreateStreamingDeployment(t *testing.T) {
name := "my-instance"
c := newStreamingStrategy(context.Background(), v1.NewJaeger(types.NamespacedName{Name: name}))
assertDeploymentsAndServicesForStreaming(t, name, c, false, false, false)
jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
c := newStreamingStrategy(context.Background(), jaeger)
assertDeploymentsAndServicesForStreaming(t, jaeger, c, false, false, false)
}

func TestStreamingKafkaProvisioning(t *testing.T) {
Expand Down Expand Up @@ -69,7 +71,7 @@ func TestCreateStreamingDeploymentOnOpenShift(t *testing.T) {
normalize(context.Background(), jaeger)

c := newStreamingStrategy(context.Background(), jaeger)
assertDeploymentsAndServicesForStreaming(t, name, c, false, true, false)
assertDeploymentsAndServicesForStreaming(t, jaeger, c, false, true, false)
}

func TestCreateStreamingDeploymentWithDaemonSetAgent(t *testing.T) {
Expand All @@ -79,7 +81,7 @@ func TestCreateStreamingDeploymentWithDaemonSetAgent(t *testing.T) {
j.Spec.Agent.Strategy = "DaemonSet"

c := newStreamingStrategy(context.Background(), j)
assertDeploymentsAndServicesForStreaming(t, name, c, true, false, false)
assertDeploymentsAndServicesForStreaming(t, j, c, true, false, false)
}

func TestCreateStreamingDeploymentWithUIConfigMap(t *testing.T) {
Expand All @@ -93,7 +95,7 @@ func TestCreateStreamingDeploymentWithUIConfigMap(t *testing.T) {
})

c := newStreamingStrategy(context.Background(), j)
assertDeploymentsAndServicesForStreaming(t, name, c, false, false, true)
assertDeploymentsAndServicesForStreaming(t, j, c, false, false, true)
}

func TestStreamingOptionsArePassed(t *testing.T) {
Expand Down Expand Up @@ -172,7 +174,8 @@ func TestAutoscaleForStreaming(t *testing.T) {
assert.Len(t, c.HorizontalPodAutoscalers(), 2)
}

func assertDeploymentsAndServicesForStreaming(t *testing.T, name string, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) {
func assertDeploymentsAndServicesForStreaming(t *testing.T, instance *v1.Jaeger, s S, hasDaemonSet bool, hasOAuthProxy bool, hasConfigMap bool) {
name := instance.Name
expectedNumObjs := 7

if hasDaemonSet {
Expand Down Expand Up @@ -206,7 +209,7 @@ func assertDeploymentsAndServicesForStreaming(t *testing.T, name string, s S, ha
consoleLinks := map[string]bool{}
if viper.GetString("platform") == v1.FlagPlatformOpenShift {
routes[name] = false
consoleLinks["jaeger--"+name] = false
consoleLinks[consolelink.Name(instance)] = false
} else {
ingresses[fmt.Sprintf("%s-query", name)] = false
}
Expand Down

0 comments on commit 8c1704f

Please sign in to comment.