Skip to content

Support for elastic agent configurations #42

Description

@brettcurtis

It would be nice to be able to setup the config for elastic agents in the helm chart (ideally as many as we like). Or is there some other way we can automate this outside the chart?

Activity

  1. chadlwilson commented on Feb 19, 2022

    @chadlwilson
    Member

    If you leave on server.shouldPreconfigure it does create a cluster profile and elastic profile. However since it makes API calls to do so, it's really only going to work without authentication enabled, and likely as a once-off.

    And it's certainly not designed to handle arbitrary user-defined profiles (from, say, a ConfigMap) and to use the API to sync them.

    But yes, depending on your setup you can definitely automate this outside the chart, or perhaps

    • use a wrapper chart to make calls to the API
    • use server.sidecarContainers within the chart if you encapsulate everything in an image to make API calls
    • or use a custom preconfigureServer possibly

    Can look at the below for inspiration.

    preconfigure_server.sh: |-
    #!/bin/bash
    SERVICE_ACCOUNT_PATH=/var/run/secrets/kubernetes.io/serviceaccount
    KUBE_TOKEN=$(<${SERVICE_ACCOUNT_PATH}/token)
    while true
    do
    status_code=$(curl 'http://localhost:8153/go/api/v1/health' -o /dev/null -w "%{http_code}")
    if [ $status_code == 200 ]; then
    break
    fi
    sleep 10
    done
    set -e
    echo "checking if server has already been configured" >> /godata/logs/preconfigure.log
    if [ -f /godata/logs/preconfigure_complete.log ]
    then
    echo "Existing server configuration found in cruise-config.xml. Skipping preconfigure_server scripts." >> /godata/logs/preconfigure.log
    exit 0
    fi
    echo "No configuration found in cruise-config.xml. Using default preconfigure_server scripts to configure server" >> /godata/logs/preconfigure.log
    echo "Trying to configure cluster profile." >> /godata/logs/preconfigure.log
    (curl --fail -i 'http://localhost:8153/go/api/admin/elastic/cluster_profiles' \
    -H'Accept: application/vnd.go.cd+json' \
    -H 'Content-Type: application/json' \
    -X POST -d '{
    "id": "k8-cluster-profile",
    "plugin_id": "cd.go.contrib.elasticagent.kubernetes",
    "properties": [
    {
    "key": "go_server_url",
    "value": "http://{{ template "gocd.fullname" . }}-server:{{ .Values.server.service.httpPort }}/go"
    },
    {
    "key": "kubernetes_cluster_url",
    "value": "https://'$KUBERNETES_SERVICE_HOST':'$KUBERNETES_SERVICE_PORT_HTTPS'"
    },
    {
    "key": "namespace",
    "value": "{{ .Release.Namespace }}"
    },
    {
    "key": "security_token",
    "value": "'$KUBE_TOKEN'"
    }
    ]
    }' >> /godata/logs/preconfigure.log)
    echo "Trying to create an elastic profile now." >> /godata/logs/preconfigure.log
    (curl --fail -i 'http://localhost:8153/go/api/elastic/profiles' \
    -H 'Accept: application/vnd.go.cd+json' \
    -H 'Content-Type: application/json' \
    -X POST -d '{
    "id": "demo-app",
    "cluster_profile_id": "k8-cluster-profile",
    "properties": [
    {
    "key": "Image",
    "value": "gocd/gocd-agent-docker-dind:v{{ .Chart.AppVersion }}"
    },
    {
    "key": "PodConfiguration",
    "value": "apiVersion: v1\nkind: Pod\nmetadata:\n name: gocd-agent-{{ `{{ POD_POSTFIX }}` }}\n labels:\n app: web\nspec:\n serviceAccountName: {{ template "gocd.agentServiceAccountName" . }}\n containers:\n - name: gocd-agent-container-{{ `{{ CONTAINER_POSTFIX }}` }}\n image: gocd/gocd-agent-docker-dind:v{{ .Chart.AppVersion }}\n securityContext:\n privileged: true"
    },
    {
    "key": "PodSpecType",
    "value": "yaml"
    },
    {
    "key": "Privileged",
    "value": "true"
    }
    ]
    }' >> /godata/logs/preconfigure.log)
    echo "Trying to creating a hello world pipeline." >> /godata/logs/preconfigure.log
    (curl --fail -i 'http://localhost:8153/go/api/admin/pipelines' \
    -H 'Accept: application/vnd.go.cd+json' \
    -H 'Content-Type: application/json' \
    -X POST -d '{ "group": "sample",
    "pipeline": {
    "label_template": "${COUNT}",
    "name": "getting_started_pipeline",
    "materials": [
    {
    "type": "git",
    "attributes": {
    "url": "https://github.com/gocd-contrib/getting-started-repo",
    "shallow_clone": true
    }
    }
    ],
    "stages": [
    {
    "name": "default_stage",
    "jobs": [
    {
    "name": "default_job",
    "elastic_profile_id": "demo-app",
    "tasks": [
    {
    "type": "exec",
    "attributes": {
    "command": "./build"
    }
    }
    ],
    "tabs": [
    {
    "name": "Sample",
    "path": "my-artifact.html"
    }
    ],
    "artifacts": [
    {
    "type": "build",
    "source": "my-artifact.html"
    }
    ]
    }
    ]
    }
    ]
    }
    }' >> /godata/logs/preconfigure.log )
    echo "Done preconfiguring the GoCD server" > /godata/logs/preconfigure_complete.log
    {{- end }}

  2. added
    help wanted
    on May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions