gocd-contrib / gomatic

A Python API for configuring GoCD
https://pypi.python.org/pypi/gomatic
MIT License
142 stars 60 forks source link

Broken ElasticAgent support (v4 vs v5 EA API) #65

Open leprechaun opened 4 years ago

leprechaun commented 4 years ago

Howdy,

Seems like the XML config format for ElasticAgents has changed with the release of 19.3.

What used to be ...

<elastic>
  <profiles>
    <profile  id="docker.unit-test" pluginId="cd.go.contrib.elastic-agent.docker">
      <property>
        <!--
          The plugin currently only supports the `Image` property,
          which allows you to select the docker image that the build should run with
        -->
        <key>Image</key>
        <value>gocdcontrib/ubuntu-docker-elastic-agent</value>
      </property>
    </profile>
  </profiles>
</elastic>

is now

  <elastic>
    <agentProfiles>
      <agentProfile id="some-id" clusterProfileId="some-cluster-profile">
        <property>
          <key>PodSpecType</key>
          <value>yaml</value>
        </property>
        <property>
          <key>Privileged</key>
          <value>true</value>
        </property>
        <property>
          <key>Image</key>
          <value>gocd/gocd-agent-docker-dind:v19.7.0</value>
        </property>
        <property>
          <key>PodConfiguration</key>
          <value>apiVersion: v1
kind: Pod
metadata:
  name: gocd-agent-{{ POD_POSTFIX }}
  labels:
    app: web
spec:
  serviceAccountName: default
  containers:
    - name: gocd-agent-container-{{ CONTAINER_POSTFIX }}
      image: gocd/gocd-agent-docker-dind:v19.7.0
      securityContext:
        privileged: true</value>
        </property>
      </agentProfile>
    </agentProfiles>
    <clusterProfiles>
      <clusterProfile id="some-cluster-profile pluginId="cd.go.contrib.elasticagent.kubernetes">
        <property>
          <key>go_server_url</key>
          <value>https://gocd-server:8154/go</value>
        </property>
        <property>
          <key>kubernetes_cluster_url</key>
          <value>https://10.96.0.1:443</value>
        </property>
        <property>
          <key>security_token</key>
          <encryptedValue>AES:SOMEREALLYLONGSTRINGYAY!!!!!1one</encryptedValue>
        </property>
        <property>
          <key>namespace</key>
          <value>ci</value>
        </property>
      </clusterProfile>
    </clusterProfiles>
  </elastic>

If I understood correctly, the higher level stanza (AgentProfiles, ClusterProfiles), are dependent on the GoCD version (and elastic agent API version, eg, v5) ... the exact confg of agent profile are dependent on the version the agent plugin (eg, kubernetes) ... which gomatic doesn't specifically care about.

So, I think this is mostly a question of detecting the GoCD server version, and using the right format. Agent specifics remain a user issue.

arvindsv commented 4 years ago

I really think gomatic should just use these migrations (appropriate ones based on a server version): https://github.com/gocd/gocd/tree/master/config/config-server/src/main/resources/upgrades

Then, any changes in GoCD's config will never matter.