gitlab-runnerのunregister

# 概要

gitlab-runnerでregisterしたrunnerをunregisterする方法

# 背景

誤ったURLでGitLab runnerを登録してしまったため、それらを削除したい。


runnerの登録状態は以下の通り。
・token=3kNjMのrunnerはGitLabから削除済みのもの
・token=p6rzqのrunnerはGitLabから削除していないもの
・どちらのrunnerもURLが誤っている。(動的IPを振ってしまった。)

```
[centos@gitlab_runner_01 ~]$ gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=11605 revision=775dd39d version=13.8.0
Listing configured runners                          ConfigFile=/home/centos/.gitlab-runner/config.toml
gitlab_runner_01                                    Executor=docker Token=3kNjMfzgcBDNnHcQH7Sp URL=http://52.193.73.91/
gitlab_runner_01                                    Executor=shell Token=p6rzqKL7RTdJf7akMgRw URL=http://52.193.73.91/
```

# うまくいった方法

config.tomlファイルを直接編集し、古いrunnerの記述をコメントアウト(多分削除しても良い)する。

```
$vi /home/centos/.gitlab-runner/config.toml
```

```toml:config.toml
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

#[[runners]]
#  name = "gitlab_runner_01"
#  url = "http://52.193.73.91/"
#  token = "3kNjMfzgcBDNnHcQH7Sp"
#  executor = "docker"
#  [runners.custom_build_dir]
#  [runners.cache]
#    [runners.cache.s3]
#    [runners.cache.gcs]
#    [runners.cache.azure]
#  [runners.docker]
#    tls_verify = false
#    image = "centos:centos7"
#    privileged = false
#    disable_entrypoint_overwrite = false
#    oom_kill_disable = false
#    disable_cache = false
#    volumes = ["/cache"]
#    shm_size = 0

#[[runners]]
#  name = "gitlab_runner_01"
#  url = "http://52.193.73.91/"
#  token = "p6rzqKL7RTdJf7akMgRw"
#  executor = "shell"
#  [runners.custom_build_dir]
#  [runners.cache]
#    [runners.cache.s3]
#    [runners.cache.gcs]
#    [runners.cache.azure]

#[[runners]]
#  name = "gitlab_runner_01"
#  url = "http://172.31.10.174/"
#  token = "zrKamUihv38tWY_EjTgQ"
#  executor = "shell"
#  [runners.custom_build_dir]
#  [runners.cache]
#    [runners.cache.s3]
#    [runners.cache.gcs]
#    [runners.cache.azure]
```

config.toml編集後のgitlab-runner list

```
$gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=1489 revision=775dd39d version=13.8.0
Listing configured runners                          ConfigFile=/home/centos/.gitlab-runner/config.toml

```



# ダメだった方法

### ダメだった1

gitlab-runner unregisterを実行→失敗
→対象のGitLabに接続できていない。(動的IPを設定したため)

```
$ sudo gitlab-runner unregister --url http://52.193.73.91 --token 3kNjMfzgcBDNnHcQH7Sp
Runtime platform                                    arch=amd64 os=linux pid=11642 revision=775dd39d version=13.8.0
Running in system-mode.                            
                                                   
ERROR: Unregistering runner from GitLab failed      runner=3kNjMfzg status=couldn't execute DELETE against http://52.193.73.91/api/v4/runners: Delete http://52.193.73.91/api/v4/runners: dial tcp 52.193.73.91:80: i/o timeout
FATAL: Failed to unregister runner 
```  

```
$ sudo gitlab-runner unregister --url http://52.193.73.91/ --token p6rzqKL7RTdJf7akMgRw
Runtime platform                                    arch=amd64 os=linux pid=11656 revision=775dd39d version=13.8.0
Running in system-mode.                            
                                                   
ERROR: Unregistering runner from GitLab failed      runner=p6rzqKL7 status=couldn't execute DELETE against http://52.193.73.91/api/v4/runners: Delete http://52.193.73.91/api/v4/runners: dial tcp 52.193.73.91:80: i/o timeout
FATAL: Failed to unregister runner               
```

### ダメだった2

gitlab-ci-multi-runner unregisterを実行→失敗
→対象のGitLabに接続できていない。(動的IPを設定したため)

```
$ sudo gitlab-ci-multi-runner unregister --url http://52.193.73.91/ --token 3kNjMfzgcBDNnHcQH7Sp
Runtime platform                                    arch=amd64 os=linux pid=11676 revision=775dd39d version=13.8.0
Running in system-mode.                            
                                                   
ERROR: Unregistering runner from GitLab failed      runner=3kNjMfzg status=couldn't execute DELETE against http://52.193.73.91/api/v4/runners: Delete http://52.193.73.91/api/v4/runners: dial tcp 52.193.73.91:80: i/o timeout
FATAL: Failed to unregister runner    
```


```
$ sudo gitlab-ci-multi-runner unregister --url http://52.193.73.91/ --token p6rzqKL7RTdJf7akMgRw
Runtime platform                                    arch=amd64 os=linux pid=11683 revision=775dd39d version=13.8.0
Running in system-mode.                            
                                                   
ERROR: Unregistering runner from GitLab failed      runner=p6rzqKL7 status=couldn't execute DELETE against http://52.193.73.91/api/v4/runners: Delete http://52.193.73.91/api/v4/runners: dial tcp 52.193.73.91:80: i/o timeout
FATAL: Failed to unregister runner  
```

### ダメだった3

gitlab-runner unregisterコマンドからの削除は成功するが、gitlab-runner listコマンドでは削除したはずのrunnerが残っている。
GitLab側のrunner一覧(Web画面)からは対象runnerが削除された。

```
$sudo gitlab-runner unregister --url http://172.31.10.174/ --token zrKamUihv38tWY_EjTgQ
Runtime platform                                    arch=amd64 os=linux pid=1361 revision=775dd39d version=13.8.0
Running in system-mode.                            
                                                   
Unregistering runner from GitLab succeeded          runner=zrKamUih
```
```
$sudo gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=1368 revision=775dd39d version=13.8.0
Listing configured runners                          ConfigFile=/etc/gitlab-runner/config.toml
gitlab_runner_01_shell                              Executor=shell Token=b-zBLW7rhG6gTZM8_KuF URL=http://172.31.10.174/

```