|
1 | 1 | /* 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' |
3 | 3 | import Operator, { ResourceEvent, ResourceEventType } from '@linode/apl-k8s-operator'
|
4 | 4 | import {
|
5 | 5 | AdminApi,
|
@@ -273,7 +273,7 @@ export const createServiceAccounts = async (
|
273 | 273 | organizations: Organization[],
|
274 | 274 | orgApi: OrganizationApi,
|
275 | 275 | ) => {
|
276 |
| - const users: User[] = await doApiCall(errors, `Getting all users`, () => adminApi.adminGetAllUsers()) |
| 276 | + const users: User[] = await doApiCall(errors, `Getting all users`, () => adminApi.adminSearchUsers()) |
277 | 277 | const filteredOrganizations = organizations.filter((org) => org.name !== 'otomi')
|
278 | 278 | await Promise.all(
|
279 | 279 | filteredOrganizations.map(async (organization) => {
|
@@ -783,14 +783,34 @@ export function buildTeamString(teamNames: any[]): string {
|
783 | 783 | return JSON.stringify(teamObject)
|
784 | 784 | }
|
785 | 785 |
|
| 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 | + |
786 | 800 | async function setGiteaOIDCConfig(update = false) {
|
787 | 801 | if (!env.oidcClientId || !env.oidcClientSecret || !env.oidcEndpoint) return
|
788 | 802 | const podNamespace = 'gitea'
|
789 |
| - const podName = 'gitea-0' |
790 | 803 | const clientID = env.oidcClientId
|
791 | 804 | const clientSecret = env.oidcClientSecret
|
792 | 805 | const discoveryURL = `${env.oidcEndpoint}/.well-known/openid-configuration`
|
793 | 806 | 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 | + |
794 | 814 | try {
|
795 | 815 | // WARNING: Dont enclose the teamNamespaceString in double quotes, this will escape the string incorrectly and breaks OIDC group mapping in gitea
|
796 | 816 | const execCommand = [
|
|
0 commit comments