Skip to content

Commit

Permalink
Fix DNS policy for host-networked pods (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport authored Jul 31, 2020
1 parent d523dcf commit 572e864
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/render/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,16 @@ func (c *apiServerComponent) apiServer() *appsv1.Deployment {
var replicas int32 = 1

hostNetwork := false
dnsPolicy := corev1.DNSClusterFirst
if c.installation.Spec.KubernetesProvider == operator.ProviderEKS &&
c.installation.Spec.CNI.Type == operator.PluginCalico {
// Workaround the fact that webhooks don't work for non-host-networked pods
// when in this networking mode on EKS, because the control plane nodes don't run
// Calico.
hostNetwork = true

// Adjust DNS policy so we can access in-cluster services.
dnsPolicy = corev1.DNSClusterFirstWithHostNet
}

d := &appsv1.Deployment{
Expand Down Expand Up @@ -577,6 +581,7 @@ func (c *apiServerComponent) apiServer() *appsv1.Deployment {
Annotations: c.tlsAnnotations,
},
Spec: corev1.PodSpec{
DNSPolicy: dnsPolicy,
NodeSelector: map[string]string{
"kubernetes.io/os": "linux",
},
Expand Down
6 changes: 6 additions & 0 deletions pkg/render/logstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,15 +945,20 @@ func (es elasticsearchComponent) eckOperatorStatefulSet() *appsv1.StatefulSet {
defaultMode := int32(420)

hostNetwork := false
dnsPolicy := corev1.DNSClusterFirst
if es.installation.Spec.KubernetesProvider == operatorv1.ProviderEKS &&
es.installation.Spec.CNI.Type == operatorv1.PluginCalico {
// Workaround the fact that webhooks don't work for non-host-networked pods
// when in this networking mode on EKS, because the control plane nodes don't run
// Calico.
hostNetwork = true

// Adjust DNS policy so we can access in-cluster services.
dnsPolicy = corev1.DNSClusterFirstWithHostNet
}

return &appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{Kind: "StatefulSet", APIVersion: "apps/v1"},
ObjectMeta: metav1.ObjectMeta{
Name: ECKOperatorName,
Namespace: ECKOperatorNamespace,
Expand All @@ -978,6 +983,7 @@ func (es elasticsearchComponent) eckOperatorStatefulSet() *appsv1.StatefulSet {
},
},
Spec: corev1.PodSpec{
DNSPolicy: dnsPolicy,
ServiceAccountName: "elastic-operator",
ImagePullSecrets: getImagePullSecretReferenceList(es.pullSecrets),
HostNetwork: hostNetwork,
Expand Down
32 changes: 32 additions & 0 deletions pkg/render/logstorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,38 @@ var _ = Describe("Elasticsearch rendering tests", func() {
Expect(nodeSelectors["k2"]).To(Equal("v2"))
})

It("should run as host network on EKS with Calico CNI", func() {
logStorage.Spec.DataNodeSelector = map[string]string{
"k1": "v1",
"k2": "v2",
}
installation.Spec.KubernetesProvider = "EKS"
installation.Spec.CNI = &operator.CNISpec{Type: "Calico"}
component := render.LogStorage(
logStorage,
installation, nil, nil, nil, nil,
esConfig,
[]*corev1.Secret{
{ObjectMeta: metav1.ObjectMeta{Name: render.TigeraElasticsearchCertSecret, Namespace: render.OperatorNamespace()}},
{ObjectMeta: metav1.ObjectMeta{Name: render.TigeraElasticsearchCertSecret, Namespace: render.ElasticsearchNamespace}},
},
[]*corev1.Secret{
{ObjectMeta: metav1.ObjectMeta{Name: render.TigeraKibanaCertSecret, Namespace: render.OperatorNamespace()}},
{ObjectMeta: metav1.ObjectMeta{Name: render.TigeraKibanaCertSecret, Namespace: render.KibanaNamespace}},
}, true,
[]*corev1.Secret{
{ObjectMeta: metav1.ObjectMeta{Name: "tigera-pull-secret"}},
}, operator.ProviderNone, nil, nil, nil, "cluster.local", true, nil)

// Host networking settings should be correct on the ECK operator.
resources, _ := component.Objects()
eckObj := GetResource(resources, "elastic-operator", "tigera-eck-operator", "apps", "v1", "StatefulSet")
Expect(eckObj).NotTo(BeNil())
eck := eckObj.(*appsv1.StatefulSet)
Expect(eck.Spec.Template.Spec.HostNetwork).To(BeTrue())
Expect(eck.Spec.Template.Spec.DNSPolicy).To(Equal(corev1.DNSClusterFirstWithHostNet))
})

It("Configures OIDC for Kibana when the OIDC configuration is provided", func() {
component := render.LogStorage(
logStorage,
Expand Down

0 comments on commit 572e864

Please sign in to comment.