Skip to content

Commit 9e3ffb0

Browse files
authored
feat: look up Gitea pod using selector (#224)
* feat: look up Gitea pod using selector * feat: improve kubeapi error handling * fix: do not catch when thrown anyway * chore: upgraded gitea client
1 parent ad1f0aa commit 9e3ffb0

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@apidevtools/json-schema-ref-parser": "9.0.6",
1313
"@kubernetes/client-node": "1.1.2",
1414
"@linode/apl-k8s-operator": "0.1.0",
15-
"@linode/gitea-client-node": "1.19.1",
15+
"@linode/gitea-client-node": "1.23.6",
1616
"@linode/harbor-client-node": "^2.2.1",
1717
"@linode/keycloak-client-node": "^15.0.0",
1818
"async-retry": "^1.3.3",

src/operator/gitea.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { Exec, KubeConfig, KubernetesObject, V1Status } from '@kubernetes/client-node'
2+
import { CoreV1Api, Exec, KubeConfig, KubernetesObject, V1Status } from '@kubernetes/client-node'
33
import Operator, { ResourceEvent, ResourceEventType } from '@linode/apl-k8s-operator'
44
import {
55
AdminApi,
@@ -273,7 +273,7 @@ export const createServiceAccounts = async (
273273
organizations: Organization[],
274274
orgApi: OrganizationApi,
275275
) => {
276-
const users: User[] = await doApiCall(errors, `Getting all users`, () => adminApi.adminGetAllUsers())
276+
const users: User[] = await doApiCall(errors, `Getting all users`, () => adminApi.adminSearchUsers())
277277
const filteredOrganizations = organizations.filter((org) => org.name !== 'otomi')
278278
await Promise.all(
279279
filteredOrganizations.map(async (organization) => {
@@ -783,14 +783,34 @@ export function buildTeamString(teamNames: any[]): string {
783783
return JSON.stringify(teamObject)
784784
}
785785

786+
async function getGiteaPodName(namespace: string): Promise<string | undefined> {
787+
const k8sApi = kc.makeApiClient(CoreV1Api)
788+
const giteaPods = await k8sApi.listNamespacedPod({
789+
namespace,
790+
labelSelector: 'app.kubernetes.io/instance=gitea,app.kubernetes.io/name=gitea',
791+
limit: 1,
792+
})
793+
if (giteaPods.items.length === 0) {
794+
console.debug('Not ready for setting up OIDC config: Gitea pod not found.')
795+
return
796+
}
797+
return giteaPods.items[0].metadata?.name
798+
}
799+
786800
async function setGiteaOIDCConfig(update = false) {
787801
if (!env.oidcClientId || !env.oidcClientSecret || !env.oidcEndpoint) return
788802
const podNamespace = 'gitea'
789-
const podName = 'gitea-0'
790803
const clientID = env.oidcClientId
791804
const clientSecret = env.oidcClientSecret
792805
const discoveryURL = `${env.oidcEndpoint}/.well-known/openid-configuration`
793806
const teamNamespaceString = buildTeamString(env.teamNames)
807+
808+
const podName = await getGiteaPodName(podNamespace)
809+
if (!podName) {
810+
console.debug('Not ready for setting up OIDC config: Name of Gitea pod not found.')
811+
return
812+
}
813+
794814
try {
795815
// WARNING: Dont enclose the teamNamespaceString in double quotes, this will escape the string incorrectly and breaks OIDC group mapping in gitea
796816
const execCommand = [

0 commit comments

Comments
 (0)