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

add agent dnsPolicy option #1370

Merged
merged 2 commits into from
Apr 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ install-tools:
golang.org/x/lint/golint \
golang.org/x/tools/cmd/goimports \
github.com/securego/gosec/cmd/[email protected] \
sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.4 \
sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 \
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
k8s.io/code-generator/cmd/[email protected] \
k8s.io/kube-openapi/cmd/[email protected]

Expand Down
2 changes: 2 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ spec:
type: object
config:
type: object
dnsPolicy:
type: string
hostNetwork:
type: boolean
image:
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ type JaegerAgentSpec struct {
// +optional
HostNetwork *bool `json:"hostNetwork,omitempty"`

// +optional
DNSPolicy v1.DNSPolicy `json:"dnsPolicy,omitempty"`

// +optional
PriorityClassName string `json:"priorityClassName,omitempty"`
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.openapi.go

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

5 changes: 5 additions & 0 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ func (a *Agent) Get() *appsv1.DaemonSet {
sort.Strings(args)

hostNetwork := false
dnsPolicy := a.jaeger.Spec.Agent.DNSPolicy
if a.jaeger.Spec.Agent.HostNetwork != nil {
hostNetwork = *a.jaeger.Spec.Agent.HostNetwork
if dnsPolicy == "" {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to set a default value here? Is that different than if a value simply isn't provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the k8s documentation, if we do not set dnsPolicy to DNSClusterFirstWithHostNet, k8s will use ClusterFirst by default, and the daemonset agent will not be able to resolve the service ip of the collector properly.

Error while dialing dial tcp: lookup jaeger-collector.observability.svc.cluster.local on {hostIP}:53: no such host

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean that DaemonSets aren't working at the moment? I think we have e2e tests exercising this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, DaemonSets should not be working now. My company has bypassed this problem by forwarding some dns domains to coredns on the physical machine.
I can try adding the corresponding test case to the e2e test.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kevinearls, we do have this, don't we?

@faceair if you could provide an e2e to prove, that would be awesome!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I modified the existing es2 test case, is this OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

}
}
priorityClassName := ""
if a.jaeger.Spec.Agent.PriorityClassName != "" {
Expand Down Expand Up @@ -173,6 +177,7 @@ func (a *Agent) Get() *appsv1.DaemonSet {
Resources: commonSpec.Resources,
VolumeMounts: commonSpec.VolumeMounts,
}},
DNSPolicy: dnsPolicy,
HostNetwork: hostNetwork,
PriorityClassName: priorityClassName,
Volumes: commonSpec.Volumes,
Expand Down
11 changes: 11 additions & 0 deletions pkg/deployment/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ func TestAgentHostNetwork(t *testing.T) {
assert.Equal(t, trueVar, dep.Spec.Template.Spec.HostNetwork)
}

func TestAgentDNSPolicyWithHostNetwork(t *testing.T) {
trueVar := true
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
jaeger.Spec.Agent.HostNetwork = &trueVar
a := NewAgent(jaeger)
dep := a.Get()
assert.Equal(t, trueVar, dep.Spec.Template.Spec.HostNetwork)
assert.Equal(t, corev1.DNSClusterFirstWithHostNet, dep.Spec.Template.Spec.DNSPolicy)
}

func TestAgentPriorityClassName(t *testing.T) {
priorityClassName := "test-class"
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/sidecar_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (suite *SidecarNamespaceTestSuite) TestSidecarNamespace() {
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}

jaegerInstanceName := "agent-as-sidecar-namespace"
j := createJaegerAgentAsSidecarInstance(jaegerInstanceName, namespace)
j := createJaegerAgentAsSidecarInstance(jaegerInstanceName, namespace, &falseVar)
defer undeployJaegerInstance(j)

dep := getVertxDefinition(namespace, map[string]string{})
Expand Down
13 changes: 8 additions & 5 deletions test/e2e/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

var ingressEnabled = true
var trueVar = true
var falseVar = true

type SidecarTestSuite struct {
suite.Suite
Expand Down Expand Up @@ -68,8 +70,8 @@ func (suite *SidecarTestSuite) AfterTest(suiteName, testName string) {
func (suite *SidecarTestSuite) TestSidecar() {
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}

firstJaegerInstanceName := "agent-as-sidecar"
firstJaegerInstance := createJaegerAgentAsSidecarInstance(firstJaegerInstanceName, namespace)
firstJaegerInstanceName := "agent-as-sidecar-with-hostnetwork"
firstJaegerInstance := createJaegerAgentAsSidecarInstance(firstJaegerInstanceName, namespace, &trueVar)
defer undeployJaegerInstance(firstJaegerInstance)

vertxDeploymentName := "vertx-create-span-sidecar"
Expand Down Expand Up @@ -100,7 +102,7 @@ func (suite *SidecarTestSuite) TestSidecar() {

/* Testing other instance */
secondJaegerInstanceName := "agent-as-sidecar2"
secondJaegerInstance := createJaegerAgentAsSidecarInstance(secondJaegerInstanceName, namespace)
secondJaegerInstance := createJaegerAgentAsSidecarInstance(secondJaegerInstanceName, namespace, &falseVar)
defer undeployJaegerInstance(secondJaegerInstance)

persisted := &appsv1.Deployment{}
Expand All @@ -109,7 +111,7 @@ func (suite *SidecarTestSuite) TestSidecar() {
Namespace: namespace,
}, persisted)
require.NoError(t, err, "Error getting jaeger instance")
require.Equal(t, "agent-as-sidecar", persisted.Labels[inject.Label])
require.Equal(t, firstJaegerInstanceName, persisted.Labels[inject.Label])

err = fw.Client.Delete(goctx.TODO(), firstJaegerInstance)
require.NoError(t, err, "Error deleting instance")
Expand Down Expand Up @@ -191,7 +193,7 @@ func getVertxDefinition(deploymentName string, annotations map[string]string) *a
return dep
}

func createJaegerAgentAsSidecarInstance(name, namespace string) *v1.Jaeger {
func createJaegerAgentAsSidecarInstance(name, namespace string, hostNetwork *bool) *v1.Jaeger {
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}

j := &v1.Jaeger{
Expand All @@ -211,6 +213,7 @@ func createJaegerAgentAsSidecarInstance(name, namespace string) *v1.Jaeger {
},
AllInOne: v1.JaegerAllInOneSpec{},
Agent: v1.JaegerAgentSpec{
HostNetwork: hostNetwork,
Options: v1.NewOptions(map[string]interface{}{
"log-level": "debug",
}),
Expand Down