Skip to content

Commit

Permalink
feat: add excludes to filter attributes from discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarschulte committed Sep 22, 2023
1 parent 0fe7cc2 commit 12a52dd
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 69 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ our [Reliability Hub](https://hub.steadybit.com/extension/com.steadybit.extensio

## Configuration

| Environment Variable | Helm value | Meaning | Required | Default |
|--------------------------------------------------|--------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|
| `STEADYBIT_EXTENSION_CONTAINER_RUNTIME` | `container.runtime` | The container runtime to user either `docker`, `containerd` or `cri-o`. Will be automatically configured if not specified. | yes | (auto) |
| `STEADYBIT_EXTENSION_CONTAINER_SOCKET` | `containerRuntimes.(docker/containerd/cri-o).socket` | The socket used to connect to the container runtime. Will be automatically configured if not specified. | yes | (auto) |
| `STEADYBIT_EXTENSION_CONTAINERD_NAMESPACE` | | The containerd namespace to use. | yes | k8s.io |
| `STEADYBIT_EXTENSION_RUNC_ROOT` | `containerRuntimes.(docker/containerd/cri-o).runcRoot` | The runc root to use. | yes | (auto) |
| `STEADYBIT_EXTENSION_RUNC_DEBUG` | | Activate debug mode for runc. | yes | k8s.io |
| `STEADYBIT_EXTENSION_RUNC_ROOTLESS` | | Set value for runc --rootless parameter | yes | k8s.io |
| `STEADYBIT_EXTENSION_RUNC_SYSTEMD_CGROUP` | | Set value for runc --systemd-cgroup parameter | yes | k8s.io |
| `STEADYBIT_EXTENSION_DISABLE_DISCOVERY_EXCLUDES` | `discovery.disableExcludes` | Ignore discovery excludes specified by `steadybit.com/discovery-disabled` | false | `false` |
| Environment Variable | Helm value | Meaning | Required | Default |
|----------------------------------------------------|--------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|----------|---------|
| `STEADYBIT_EXTENSION_CONTAINER_RUNTIME` | `container.runtime` | The container runtime to user either `docker`, `containerd` or `cri-o`. Will be automatically configured if not specified. | yes | (auto) |
| `STEADYBIT_EXTENSION_CONTAINER_SOCKET` | `containerRuntimes.(docker/containerd/cri-o).socket` | The socket used to connect to the container runtime. Will be automatically configured if not specified. | yes | (auto) |
| `STEADYBIT_EXTENSION_CONTAINERD_NAMESPACE` | | The containerd namespace to use. | yes | k8s.io |
| `STEADYBIT_EXTENSION_RUNC_ROOT` | `containerRuntimes.(docker/containerd/cri-o).runcRoot` | The runc root to use. | yes | (auto) |
| `STEADYBIT_EXTENSION_RUNC_DEBUG` | | Activate debug mode for runc. | yes | k8s.io |
| `STEADYBIT_EXTENSION_RUNC_ROOTLESS` | | Set value for runc --rootless parameter | yes | k8s.io |
| `STEADYBIT_EXTENSION_RUNC_SYSTEMD_CGROUP` | | Set value for runc --systemd-cgroup parameter | yes | k8s.io |
| `STEADYBIT_EXTENSION_DISABLE_DISCOVERY_EXCLUDES` | `discovery.disableExcludes` | Ignore discovery excludes specified by `steadybit.com/discovery-disabled` | false | `false` |
| `STEADYBIT_EXTENSION_DISCOVERY_ATTRIBUTE_EXCLUDES` | `discovery.attributes.excludes` | List of Target Attributes which will be excluded during discovery. Checked by key equality and supporting trailing "*" | false | |

The extension supports all environment variables provided
by [steadybit/extension-kit](https://github.com/steadybit/extension-kit#environment-variables).
Expand Down
2 changes: 2 additions & 0 deletions charts/steadybit-extension-container/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ spec:
value: {{ .Values.containerPorts.http | quote }}
- name: STEADYBIT_EXTENSION_HEALTH_PORT
value: {{ .Values.containerPorts.health | quote }}
- name: STEADYBIT_EXTENSION_DISCOVERY_ATTRIBUTE_EXCLUDES
value: {{ join "," .Values.discovery.attributes.excludes | quote }}
{{- if .Values.discovery.disableExcludes }}
- name: STEADYBIT_EXTENSION_DISABLE_DISCOVERY_EXCLUDES
value: "true"
Expand Down
3 changes: 3 additions & 0 deletions charts/steadybit-extension-container/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ securityContext:
discovery:
# discovery.disableExcludes -- Ignore discovery excludes specified by `steadybit.com/discovery-disabled` (mainly for internal use)
disableExcludes: false
attributes:
# container.discovery.attributes.excludes -- List of attributes to exclude from container discovery.
excludes: [ ]
23 changes: 12 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (
)

type Specification struct {
ContainerSocket string `json:"containerSocket" split_words:"true" required:"false"`
ContainerRuntime string `json:"containerRuntime" split_words:"true" required:"false"`
ContainerdNamespace string `json:"containerdNamespace" split_words:"true" required:"true" default:"k8s.io"`
RuncRoot string `json:"runcRoot" split_words:"true" required:"false"`
RuncRootless string `json:"runcRootless" split_words:"true" required:"false"`
RuncSystemdCgroup bool `json:"runcSystemdCgroup" split_words:"true" required:"false"`
RuncDebug bool `json:"runcDebug" split_words:"true" required:"false"`
DisableDiscoveryExcludes bool `required:"false" split_words:"true" default:"false"`
DiscoveryCallInterval string `json:"discoveryCallInterval" split_words:"true" required:"false" default:"1m"`
Port uint16 `json:"port" split_words:"true" required:"false" default:"8086"`
HealthPort uint16 `json:"healthPort" split_words:"true" required:"false" default:"8082"`
ContainerSocket string `json:"containerSocket" split_words:"true" required:"false"`
ContainerRuntime string `json:"containerRuntime" split_words:"true" required:"false"`
ContainerdNamespace string `json:"containerdNamespace" split_words:"true" required:"true" default:"k8s.io"`
RuncRoot string `json:"runcRoot" split_words:"true" required:"false"`
RuncRootless string `json:"runcRootless" split_words:"true" required:"false"`
RuncSystemdCgroup bool `json:"runcSystemdCgroup" split_words:"true" required:"false"`
RuncDebug bool `json:"runcDebug" split_words:"true" required:"false"`
DisableDiscoveryExcludes bool `required:"false" split_words:"true" default:"false"`
DiscoveryCallInterval string `json:"discoveryCallInterval" split_words:"true" required:"false" default:"1m"`
Port uint16 `json:"port" split_words:"true" required:"false" default:"8086"`
HealthPort uint16 `json:"healthPort" split_words:"true" required:"false" default:"8082"`
DiscoveryAttributeExcludes []string `json:"discoveryAttributeExcludes" split_words:"true" required:"false"`
}

var (
Expand Down
17 changes: 9 additions & 8 deletions e2e/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestWithMinikube(t *testing.T) {
return []string{
"--set", fmt.Sprintf("container.runtime=%s", m.Runtime),
"--set", "logging.level=trace",
"--set", "discovery.attributes.excludes={container.label.*}",
}
},
}
Expand Down Expand Up @@ -892,12 +893,12 @@ func testStopContainer(t *testing.T, m *e2e.Minikube, e *e2e.Extension) {
config := struct {
Graceful bool `json:"graceful"`
}{Graceful: true}
go func() {
action, err := e.RunAction(fmt.Sprintf("%s.stop", extcontainer.BaseActionID), target, config, executionContext)
defer func() { _ = action.Cancel() }()
require.NoError(t, err)
require.NoError(t, action.Wait())
}()
go func() {
action, err := e.RunAction(fmt.Sprintf("%s.stop", extcontainer.BaseActionID), target, config, executionContext)
defer func() { _ = action.Cancel() }()
require.NoError(t, err)
require.NoError(t, action.Wait())
}()
action2, err2 := e.RunAction(fmt.Sprintf("%s.stop", extcontainer.BaseActionID), target2, config, executionContext)

defer func() { _ = action2.Cancel() }()
Expand All @@ -912,7 +913,7 @@ func testStopContainer(t *testing.T, m *e2e.Minikube, e *e2e.Extension) {
require.NotNil(t, status)
assert.NotNil(t, status.State.Terminated, "container should be terminated")

status2, err := nginx2.ContainerStatus()
status2, err := nginx2.ContainerStatus()
require.NoError(t, err)
require.NotNil(t, status2)
assert.NotNil(t, status2.State.Terminated, "container should be terminated")
Expand All @@ -936,7 +937,7 @@ func testDiscovery(t *testing.T, m *e2e.Minikube, e *e2e.Extension) {
})
require.NoError(t, err)
assert.Equal(t, target.TargetType, "com.steadybit.extension_container.container")

assert.NotContains(t, target.Attributes, "container.label.maintainer")
targets, err := e.DiscoverTargets("com.steadybit.extension_container.container")
require.NoError(t, err)
for _, target := range targets {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/steadybit/action-kit/go/action_kit_commons v1.0.8
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.6
github.com/steadybit/action-kit/go/action_kit_test v1.2.0
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.4.2
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.4.3-0.20230922132604-3cad34b4dd5b
github.com/steadybit/discovery-kit/go/discovery_kit_test v1.0.2
github.com/steadybit/extension-kit v1.8.8
github.com/stretchr/testify v1.8.4
Expand Down
Loading

0 comments on commit 12a52dd

Please sign in to comment.