mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-12 10:54:09 +00:00
enhance(k8s): reach Kubernetes services by their id when it is a DNS subdomain (#1320)
On Kubernetes a service is reached by its id made a DNS label, so some service ids might become unreachable. For example, the `devstoreaccount1.azurite.local` service of Gitea's [MSSQL tests](https://github.com/go-gitea/gitea/blob/2fe74d3cdd5184a7e22e32e47772caa78d077489/.github/workflows/pull-db-tests.yml#L229) is only in the pod's hosts as `devstoreaccount1-azurite-local`, while the tests connect to the id as written. Container names must be DNS labels, but `hostAliases` accepts DNS subdomains, so an id that is one is now added there too, and to `no_proxy`, as on Docker where a service is reached by its id. The warning for a service not reachable by its id now also covers ids that differ only in case, as Kubernetes hostnames are lowercase. --------- Co-authored-by: silverwind <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1320 Reviewed-by: Lunny Xiao <[email protected]> Reviewed-by: bircni <[email protected]> Reviewed-by: silverwind <[email protected]> Co-authored-by: Zettat123 <[email protected]>
This commit is contained in:
1 parent
b9aa47d1a5
commit
755af87095
4 files changed
+39
-11
No files matched your search
@@ -129,6 +129,19 @@ func serveLocalExec(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubernetesServiceHostnames(t *testing.T) {
|
||||
for id, hostnames := range map[string][]string{
|
||||
"db": {"db"},
|
||||
"My_DB": {"my-db"},
|
||||
"devstoreaccount1.azurite.local": {"devstoreaccount1-azurite-local", "devstoreaccount1.azurite.local"},
|
||||
"DB.Local": {"db-local", "db.local"},
|
||||
strings.Repeat("a", 64): {strings.Repeat("a", 63), strings.Repeat("a", 64)},
|
||||
strings.Repeat("a", 254): {strings.Repeat("a", 63)},
|
||||
} {
|
||||
assert.Equal(t, hostnames, KubernetesServiceHostnames(id), id)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubernetesPodRunsJobThroughAPI(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("uses POSIX shell")
|
||||
|
||||
Reference in new issue
Block a user