Skip to content

Commit

Permalink
Add new flag serviceMesh.enabled (#168)
Browse files Browse the repository at this point in the history
* Add new flag serviceMesh.enabled

Signed-off-by: Jefiya M J <[email protected]>

* Add serviceMesh.enabled field

Signed-off-by: Jefiya M J <[email protected]>

* feat(servicemesh): Propagate serviceMesh.enabled

The serviceMesh.enabled boolean is translated into a
ENABLE_AGENT_SOCKET environment variable on the agent DaemonSet which
schedules the pods with the environment variable exposed to the
agent container.

* chore(fix): Fix unit test to include new env var

* add unit test to include new env var

Signed-off-by: Jefiya M J <[email protected]>

---------

Signed-off-by: Jefiya M J <[email protected]>
Co-authored-by: Konrad Ohms <[email protected]>
  • Loading branch information
Jefiya-MJ and konrad-ohms authored Jun 24, 2024
1 parent 0f70da8 commit 67b6168
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 1 deletion.
9 changes: 9 additions & 0 deletions api/v1/inline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ type BaseAgentSpec struct {
// +kubebuilder:validation:Optional
Host HostSpec `json:"host,omitempty"`

// ServiceMesh sets the ENABLE_AGENT_SOCKET environment variable.
// +kubebuilder:validation:Optional
ServiceMesh ServiceMeshSpec `json:"serviceMesh,omitempty"`

// Override for the Maven repository URL when the Agent needs to connect to a locally provided Maven repository 'proxy'
// Alternative to `Host` for referencing a different Maven repo.
// +kubebuilder:validation:Optional
Expand Down Expand Up @@ -263,6 +267,11 @@ type HostSpec struct {
Repository string `json:"repository,omitempty"`
}

type ServiceMeshSpec struct {
// +kubebuilder:validation:Optional
Enabled bool `json:"enabled,omitempty"`
}

type Prometheus struct {
// +kubebuilder:validation:Optional
RemoteWrite Enabled `json:"remoteWrite,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions api/v1/instanaagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type InstanaAgentSpec struct {
// Zones can be used to specify agents in multiple zones split across different nodes in the cluster
// +kubebuilder:validation:Optional
Zones []Zone `json:"zones,omitempty"`

// +kubebuilder:validation:Optional
ServiceMesh ServiceMeshSpec `json:"serviceMesh,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
17 changes: 17 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions config/samples/instana_v1_extended_instanaagent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spec:
# agent.pod.limits.cpu sets the CPU units allocation limits for the agent pods.
cpu: "1.5"

serviceMesh:
# agent.serviceMesh.enabled sets the Instana agent's communication direction with JVMs.
# To allow communication to be directed to the agent, set this variable to true.
enabled: true

# agent.host.repository sets a host path to be mounted as the agent maven repository (for debugging or development purposes)
# host:
# repository: ""
Expand Down
1 change: 1 addition & 0 deletions pkg/k8s/object/builders/agent/daemonset/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (d *daemonSetBuilder) getEnvVars() []corev1.EnvVar {
env.InstanaAgentPodNameEnv,
env.PodIPEnv,
env.K8sServiceDomainEnv,
env.EnableAgentSocketEnv,
)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/k8s/object/builders/agent/daemonset/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func TestDaemonSetBuilder_getEnvVars(t *testing.T) {
env.InstanaAgentPodNameEnv,
env.PodIPEnv,
env.K8sServiceDomainEnv,
env.EnableAgentSocketEnv,
).
Return(expected)

Expand Down
16 changes: 16 additions & 0 deletions pkg/k8s/object/builders/common/env/env.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// /*
// (c) Copyright IBM Corp. 2024
// (c) Copyright Instana Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// */
package env

import (
Expand Down
21 changes: 21 additions & 0 deletions pkg/k8s/object/builders/common/env/env_builder.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// /*
// (c) Copyright IBM Corp. 2024
// (c) Copyright Instana Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// */
//

package env

import (
Expand Down Expand Up @@ -45,6 +63,7 @@ const (
PodUIDEnv
PodNamespaceEnv
K8sServiceDomainEnv
EnableAgentSocketEnv
)

type EnvBuilder interface {
Expand Down Expand Up @@ -122,6 +141,8 @@ func (e *envBuilder) getBuilder(envVar EnvVar) func() optional.Optional[corev1.E
return e.podNamespaceEnv
case K8sServiceDomainEnv:
return e.k8sServiceDomainEnv
case EnableAgentSocketEnv:
return e.enableAgentSocketEnv
default:
panic(errors.New("unknown environment variable requested"))
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/k8s/object/builders/common/env/env_builder_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// /*
// (c) Copyright IBM Corp. 2024
// (c) Copyright Instana Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// */
package env

import (
Expand Down Expand Up @@ -32,7 +48,7 @@ func assertAllElementsUnique[T comparable](assertions *require.Assertions, list
}

func TestEnvBuilder_getBuilder(t *testing.T) {
const numDefinedEnvVars = 31
const numDefinedEnvVars = 32

t.Run(
"each_defined_var_has_unique_function", func(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions pkg/k8s/object/builders/common/env/env_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// /*
// (c) Copyright IBM Corp. 2024
// (c) Copyright Instana Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// */
package env

import (
Expand Down
22 changes: 22 additions & 0 deletions pkg/k8s/object/builders/common/env/vars.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// /*
// (c) Copyright IBM Corp. 2024
// (c) Copyright Instana Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// */
//

package env

import (
Expand Down Expand Up @@ -137,6 +155,10 @@ func (e *envBuilder) httpsProxyEnv() optional.Optional[corev1.EnvVar] {
)
}

func (e *envBuilder) enableAgentSocketEnv() optional.Optional[corev1.EnvVar] {
return fromCRField("ENABLE_AGENT_SOCKET", e.agent.Spec.Agent.ServiceMesh.Enabled)
}

// Static

func (e *envBuilder) backendURLEnv() optional.Optional[corev1.EnvVar] {
Expand Down
22 changes: 22 additions & 0 deletions pkg/k8s/object/builders/common/env/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,28 @@ func TestEnvBuilder_httpsProxyEnv(t *testing.T) {
}
}

func TestEnvBuilder_enableAgentSocketEnv(t *testing.T) {
const expectedValue = true

testFromCRField(
&crFieldVarTest{
t: t,
getMethod: func(builder *envBuilder) func() optional.Optional[corev1.EnvVar] {
return builder.enableAgentSocketEnv
},
expectedName: "ENABLE_AGENT_SOCKET",
expectedValue: strconv.FormatBool(expectedValue),
agentSpec: instanav1.InstanaAgentSpec{
Agent: instanav1.BaseAgentSpec{
ServiceMesh: instanav1.ServiceMeshSpec{
Enabled: expectedValue,
},
},
},
},
)
}

func TestEnvBuilder_backendURLEnv(t *testing.T) {
testLiteralAlways(
&literalAlwaysTest{
Expand Down

0 comments on commit 67b6168

Please sign in to comment.