-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from Dynatrace/feature/edge_connect
Feature/edge connect
- Loading branch information
Showing
13 changed files
with
273 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
user-skel/ansible_collections/ace_box/ace_box/roles/dt-edge-connect/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# dt-edge-connect | ||
|
||
This currated role can be used to deploy the Dynatrace [Edge Connect](https://docs.dynatrace.com/docs/setup-and-configuration/edgeconnect) component in your k8s cluster. | ||
|
||
## Using the role | ||
|
||
### Role Requirements | ||
This role depends on the following roles to be deployed beforehand: | ||
|
||
```yaml | ||
- include_role: | ||
name: k3s | ||
``` | ||
```yaml | ||
- include_role: | ||
name: dt-operator | ||
``` | ||
### Deploying dt-edge-connect | ||
`dt-edge-connect` gets installed along with the Dynatrace Operator. In order to deploy `dt-edge-connect`, add the following variable to the dt-operator role: | ||
|
||
```yaml | ||
- include_role: | ||
name: dt-edge-connect | ||
``` | ||
|
||
Once the role is completed, the following variables are available: | ||
- `k8s_cluster_uid` | ||
- `edge_connect_token` | ||
|
||
In order to use dt-edge-connect in a [Kubernetes Workflow Action](https://docs.dynatrace.com/docs/analyze-explore-automate/workflows/actions/kubernetes-automation/kubernetes-workflow-actions), a connection setting is needed. The `dt-edge-connect` role will automatically create a connection for you that you can use in a Kubernetes Workflow Action. | ||
|
||
If you want to automatically provision a Kubernetes Workflow Action via monaco, then you need also the connection as-code, in order to reference one configuration with the other. Then you need to store the variables as environment variables, in order to call them from the monaco configuration file. Check the files under `dt-edge-connect/files/monaco/k8s-connector` as an example: | ||
|
||
```yaml | ||
configs: | ||
- id: k8s_connector | ||
config: | ||
parameters: | ||
k8sToken: | ||
type: environment | ||
name: k8s_cluster_uid | ||
k8sUid: | ||
type: environment | ||
name: edge_connect_token | ||
template: k8s-connector.json | ||
skip: true | ||
type: | ||
settings: | ||
schema: app:dynatrace.kubernetes.connector:connection | ||
schemaVersion: 0.1.8 | ||
scope: environment | ||
``` | ||
|
||
If you are running monaco from Gitlab, this is how you can create enviroment variables: | ||
|
||
```yaml | ||
- name: Gitlab - Additional Environment Variables | ||
include_role: | ||
name: gitlab | ||
tasks_from: ensure-group-var | ||
vars: | ||
gitlab_var_key: "{{ item.key }}" | ||
gitlab_var_value: "{{ item.value }}" | ||
loop: | ||
- { | ||
key: "k8s_cluster_uid", | ||
value: "{{k8s_cluster_uid}}", | ||
} | ||
- { | ||
key: "edge_connect_token", | ||
value: "{{edge_connect_token}}", | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
user-skel/ansible_collections/ace_box/ace_box/roles/dt-edge-connect/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2024 Dynatrace LLC | ||
# | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
--- | ||
cluster_ip: "{{hostvars[inventory_hostname]['ansible_default_ipv4']['address']}}" | ||
edge_connect_name: "edge-connect-k8s-hot" | ||
dynatrace_api_version: v1alpha1 |
17 changes: 17 additions & 0 deletions
17
...collections/ace_box/ace_box/roles/dt-edge-connect/files/monaco/k8s-connection/config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
configs: | ||
- id: k8s_connector | ||
config: | ||
parameters: | ||
k8sToken: | ||
type: environment | ||
name: K8S_TOKEN | ||
k8sUid: | ||
type: environment | ||
name: K8S_UID | ||
template: k8s-connector.json | ||
skip: true | ||
type: | ||
settings: | ||
schema: app:dynatrace.kubernetes.connector:connection | ||
schemaVersion: 0.1.8 | ||
scope: environment |
6 changes: 6 additions & 0 deletions
6
...ions/ace_box/ace_box/roles/dt-edge-connect/files/monaco/k8s-connection/k8s-connector.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "edge-connect-k8s-hot", | ||
"namespace": "dynatrace", | ||
"uid": "{{.k8sUid}}", | ||
"token": "{{.k8sToken}}" | ||
} |
42 changes: 42 additions & 0 deletions
42
...ansible_collections/ace_box/ace_box/roles/dt-edge-connect/tasks/generate-credentials.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
- name: Get k8s cluster info | ||
kubernetes.core.k8s_info: | ||
api_version: v1 | ||
kind: Namespace | ||
name: kube-system | ||
register: k8s_cluster_uid | ||
|
||
- name: Set variable for k8s cluster id | ||
set_fact: | ||
k8s_cluster_uid: "{{k8s_cluster_uid.resources[0].metadata.uid}}" | ||
|
||
- name: Generate token workflow connection | ||
shell: | | ||
echo dt0e01.`openssl rand -out /dev/stdout 15 | base32 | tr '[:lower:]' '[:upper:]'`.`openssl rand -out /dev/stdout 40 | base32 | tr '[:lower:]' '[:upper:]'` | ||
register: edge_connect_token | ||
|
||
- name: Generate variable for token | ||
set_fact: | ||
edge_connect_token: "{{edge_connect_token.stdout}}" | ||
|
||
- include_role: | ||
name: dt-access-token | ||
vars: | ||
access_token_var_name: "k8s_settings_token" | ||
access_token_scope: ["settings.write", "settings.read"] | ||
|
||
# - name: Generate random number for an auxiliar connection to the monaco (optional) one | ||
# set_fact: | ||
# r: "{{ 1000 | random }}" | ||
|
||
# - name: Configure k8s workflow action connector setting | ||
# uri: | ||
# url: "{{ dynatrace_tenant_url }}/api/v2/settings/objects?validateOnly=false" | ||
# method: POST | ||
# body: "[{\"schemaId\": \"app:dynatrace.kubernetes.connector:connection\",\"schemaVersion\": \"0.1.5\",\"scope\": \"environment\",\"value\": {\"name\": \"edge-connect-{{r}}\",\"uid\": \"{{ k8s_cluster_uid }}\",\"namespace\": \"dynatrace\",\"token\": \"{{edge_connect_token}}\"}}]" | ||
# body_format: json | ||
# headers: | ||
# Authorization: 'Api-Token {{ k8s_settings_token }}' | ||
# Content-Type: 'application/json; charset=utf-8' | ||
# accept: application/json | ||
# register: post_output |
56 changes: 56 additions & 0 deletions
56
user-skel/ansible_collections/ace_box/ace_box/roles/dt-edge-connect/tasks/main.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
- name: edge connect service account | ||
kubernetes.core.k8s: | ||
state: present | ||
src: "{{ role_path }}/templates/edgeconnect-serviceaccount.yaml" | ||
|
||
- name: edge connect role | ||
kubernetes.core.k8s: | ||
state: present | ||
src: "{{ role_path }}/templates/edgeconnect-role.yaml" | ||
|
||
- name: edge connect role binding | ||
kubernetes.core.k8s: | ||
state: present | ||
src: "{{ role_path }}/templates/edgeconnect-rolebinding.yaml" | ||
|
||
- set_fact: | ||
dt_tenant_gen3_no_protocol: "{{ extra_vars.dt_environment_url_gen3 | regex_search('[^\/\/]*$') }}" | ||
|
||
- name: Template secret for edge connect | ||
ansible.builtin.template: | ||
src: "edgeconnect-oauth-secret.yaml.j2" | ||
dest: "{{ role_path }}/templates/edgeconnect-oauth-secret.yaml" | ||
owner: "{{ ace_box_user }}" | ||
group: "{{ ace_box_user }}" | ||
mode: "0644" | ||
|
||
- name: Apply secret for edge connect | ||
kubernetes.core.k8s: | ||
state: present | ||
src: "{{ role_path }}/templates/edgeconnect-oauth-secret.yaml" | ||
delay: 5 | ||
|
||
- set_fact: | ||
tenant_id: "{{ dt_tenant_gen3_no_protocol | split('.') }}" | ||
|
||
- name: Print response | ||
debug: "msg='{{ tenant_id[0] }}'" | ||
|
||
- name: Template edge connect | ||
ansible.builtin.template: | ||
src: "edgeconnect.yaml.j2" | ||
dest: "{{ role_path }}/templates/edgeconnect.yaml" | ||
owner: "{{ ace_box_user }}" | ||
group: "{{ ace_box_user }}" | ||
mode: "0644" | ||
|
||
- name: Apply edge connect | ||
kubernetes.core.k8s: | ||
state: present | ||
src: "{{ role_path }}/templates/edgeconnect.yaml" | ||
delay: 5 | ||
|
||
- name: Generate credentials | ||
include_role: | ||
name: edge-connect | ||
tasks_from: generate-credentials |
8 changes: 8 additions & 0 deletions
8
...lections/ace_box/ace_box/roles/dt-edge-connect/templates/edgeconnect-oauth-secret.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: edgeconnect-oauth | ||
namespace: dynatrace | ||
data: | ||
oauth-client-id: {{ extra_vars.dt_oauth_client_id | b64encode }} | ||
oauth-client-secret: {{ extra_vars.dt_oauth_client_secret | b64encode }} |
9 changes: 9 additions & 0 deletions
9
...ansible_collections/ace_box/ace_box/roles/dt-edge-connect/templates/edgeconnect-role.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: edgeconnect-deployment-rollout-restart | ||
namespace: default | ||
rules: | ||
- apiGroups: ["apps"] | ||
resources: ["deployments"] | ||
verbs: ["get", "patch"] |
13 changes: 13 additions & 0 deletions
13
..._collections/ace_box/ace_box/roles/dt-edge-connect/templates/edgeconnect-rolebinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: edgeconnect-deployment-rollout-restart | ||
namespace: default | ||
roleRef: | ||
kind: Role | ||
name: edgeconnect-deployment-rollout-restart | ||
apiGroup: rbac.authorization.k8s.io | ||
subjects: | ||
- kind: ServiceAccount | ||
name: edgeconnect-deployment-rollout-restarter | ||
namespace: dynatrace |
5 changes: 5 additions & 0 deletions
5
...llections/ace_box/ace_box/roles/dt-edge-connect/templates/edgeconnect-serviceaccount.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: edgeconnect-deployment-rollout-restarter | ||
namespace: dynatrace |
15 changes: 15 additions & 0 deletions
15
...l/ansible_collections/ace_box/ace_box/roles/dt-edge-connect/templates/edgeconnect.yaml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: dynatrace.com/{{dynatrace_api_version}} | ||
kind: EdgeConnect | ||
metadata: | ||
name: {{edge_connect_name}} | ||
namespace: dynatrace | ||
spec: | ||
apiServer: {{dt_tenant_gen3_no_protocol}} | ||
serviceAccountName: edgeconnect-deployment-rollout-restarter | ||
oauth: | ||
provisioner: true | ||
clientSecret: edgeconnect-oauth | ||
endpoint: {{ extra_vars.dt_oauth_sso_endpoint }} | ||
resource: urn:dtenvironment:{{tenant_id}} | ||
kubernetesAutomation: | ||
enabled: true |
7 changes: 7 additions & 0 deletions
7
...ections/ace_box/ace_box/roles/dt-edge-connect/templates/new-edgeconnect-dt-config.json.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "k8s-hot", | ||
"hostPatterns": [ | ||
"{{ cluster_ip }}" | ||
], | ||
"oauthClientId": "{{ extra_vars.dt_oauth_client_id }}" | ||
} |