Skip to content

Commit

Permalink
feat: gitea operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ferruhcihan committed Jun 21, 2024
1 parent 44eeeca commit 782cd40
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
18 changes: 16 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
// language - current active spelling language
"language": "en",
// words - list of words to be always considered correct
"words": ["camelcase", "creds", "kubernetes", "openid", "otomi", "redkubes", "robotv"],
"words": [
"argocd",
"camelcase",
"creds",
"gitea",
"kubernetes",
"oidc",
"openid",
"otomi",
"redkubes",
"robotv",
"tekton"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
// For example "hte" should be "the"
"flagWords": ["hte"]
"flagWords": [
"hte"
]
}
22 changes: 8 additions & 14 deletions src/operator/gitea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ if (process.env.KUBERNETES_SERVICE_HOST && process.env.KUBERNETES_SERVICE_PORT)
} else {
kc.loadFromDefault()
}
const k8sApi = kc.makeApiClient(k8s.CoreV1Api)

// Callbacks
const secretsAndConfigmapsCallback = async (e: any) => {
Expand Down Expand Up @@ -200,9 +199,9 @@ async function checkAndExecute() {
await setGiteaOIDCConfig()
}

// Check and execute execGiteaCLICommand if dependencies changed
// Check and execute setGiteaGroupMapping if dependencies changed
if (!currentState.teamNames || currentState.teamNames !== lastState.teamNames) {
await execGiteaCLICommand('gitea', 'gitea-0')
await setGiteaGroupMapping('gitea', 'gitea-0')
}

// Update last known state
Expand All @@ -211,9 +210,6 @@ async function checkAndExecute() {

async function runSetupGitea() {
try {
// await setupGitea() // deps: !env.giteaPassword || !env.teamConfig
// await setGiteaOIDCConfig() // deps: !env.oidcClientId || !env.oidcClientSecret || !env.oidcEndpoint
// await execGiteaCLICommand('gitea', 'gitea-0') // deps: !env.teamNames
await checkAndExecute()
} catch (error) {
console.debug('Error could not run setup gitea', error)
Expand Down Expand Up @@ -247,7 +243,6 @@ async function upsertTeam(
}

async function upsertRepo(
existingTeams: Team[] = [],
existingRepos: Repository[] = [],
orgApi: OrganizationApi,
repoApi: RepositoryApi,
Expand Down Expand Up @@ -352,14 +347,13 @@ async function createOrgAndTeams(orgApi: OrganizationApi, existingTeams: Team[],
async function createReposAndAddToTeam(
orgApi: OrganizationApi,
repoApi: RepositoryApi,
existingTeams: Team[],
existingRepos: Repository[],
repoOption: CreateRepoOption,
) {
// create main org repo: otomi/values
await upsertRepo(existingTeams, existingRepos, orgApi, repoApi, repoOption)
await upsertRepo(existingRepos, orgApi, repoApi, repoOption)
// create otomi/charts repo for auto image updates
await upsertRepo(existingTeams, existingRepos, orgApi, repoApi, { ...repoOption, name: otomiChartsRepoName })
await upsertRepo(existingRepos, orgApi, repoApi, { ...repoOption, name: otomiChartsRepoName })

// add repo: otomi/values to the team: otomi-viewer
await doApiCall(
Expand Down Expand Up @@ -402,7 +396,7 @@ async function setupGitea() {
name: otomiValuesRepoName,
_private: true,
}
await createReposAndAddToTeam(orgApi, repoApi, existingTeams, existingRepos, repoOption)
await createReposAndAddToTeam(orgApi, repoApi, existingRepos, repoOption)

// check for specific hooks
await addTektonHook(repoApi)
Expand All @@ -414,7 +408,7 @@ async function setupGitea() {
teamIds.map(async (teamId) => {
const name = `team-${teamId}-argocd`
const option = { ...repoOption, autoInit: true, name }
return upsertRepo(existingTeams, existingRepos, orgApi, repoApi, option, `team-${teamId}`)
return upsertRepo(existingRepos, orgApi, repoApi, option, `team-${teamId}`)
}),
)
if (errors.length) {
Expand All @@ -425,7 +419,7 @@ async function setupGitea() {
}
}

// Exec Gitea CLI Functions
// Set Gitea Functions
export function buildTeamString(teamNames: any[]): string {
if (teamNames === undefined) return '{}'
const teamObject: groupMapping = {}
Expand All @@ -435,7 +429,7 @@ export function buildTeamString(teamNames: any[]): string {
return JSON.stringify(teamObject)
}

async function execGiteaCLICommand(podNamespace: string, podName: string) {
async function setGiteaGroupMapping(podNamespace: string, podName: string) {
if (!env.teamNames) {
console.debug('No team namespaces found with type=team configuration')
return
Expand Down

0 comments on commit 782cd40

Please sign in to comment.