Skip to content

Commit 852bcd2

Browse files
merllsvcAPLBot
andauthored
chore: upgrade Gitea to 1.25.2 (#2758)
Co-authored-by: svcAPLBot <[email protected]>
1 parent f525da1 commit 852bcd2

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed

charts/gitea/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ annotations:
1111
- kind: changed
1212
description: update alpine/helm docker tag to v3.19.0 (#954)
1313
apiVersion: v2
14-
appVersion: 1.24.7
14+
appVersion: 1.25.2
1515
dependencies:
1616
- condition: postgresql.enabled
1717
name: postgresql

src/common/k8s.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
KubeConfig,
88
PatchStrategy,
99
setHeaderOptions,
10+
V1Deployment,
1011
V1Pod,
1112
V1PodList,
1213
V1ResourceRequirements,
@@ -169,6 +170,45 @@ describe('StatefulSet tests', () => {
169170
jest.clearAllMocks()
170171
})
171172

173+
describe('getPodsOfDeployment', () => {
174+
it('should return pods matching the Deployment label selector', async () => {
175+
const mockDeployment = {
176+
spec: {
177+
selector: {
178+
matchLabels: { app: 'my-app' },
179+
},
180+
},
181+
}
182+
183+
const mockPodList: V1PodList = {
184+
items: [{ metadata: { name: 'pod-1' } }, { metadata: { name: 'pod-2' } }],
185+
} as V1PodList
186+
187+
mockAppsApi.readNamespacedDeployment.mockResolvedValue(mockDeployment as any)
188+
mockCoreApi.listNamespacedPod.mockResolvedValue(mockPodList as any)
189+
190+
const pods = await k8s.getPodsOfDeployment(mockAppsApi, mockCoreApi, 'my-deploy', 'my-namespace')
191+
expect(mockAppsApi.readNamespacedDeployment).toHaveBeenCalledWith({
192+
name: 'my-deploy',
193+
namespace: 'my-namespace',
194+
})
195+
expect(mockCoreApi.listNamespacedPod).toHaveBeenCalledWith({
196+
labelSelector: 'app=my-app',
197+
namespace: 'my-namespace',
198+
})
199+
expect(pods).toEqual(mockPodList)
200+
})
201+
202+
it('should throw an error if matchLabels is missing', async () => {
203+
const mockDeployment: V1Deployment = {} as V1Deployment
204+
mockAppsApi.readNamespacedDeployment.mockResolvedValue(mockDeployment as any)
205+
206+
await expect(k8s.getPodsOfDeployment(mockAppsApi, mockCoreApi, 'my-deploy', 'my-namespace')).rejects.toThrow(
207+
'Deployment my-deploy does not have matchLabels',
208+
)
209+
})
210+
})
211+
172212
describe('getPodsOfStatefulSet', () => {
173213
it('should return pods matching the StatefulSet label selector', async () => {
174214
const mockStatefulSet = {

src/common/k8s.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,28 @@ export async function createUpdateConfigMap(
629629
}
630630
}
631631

632+
export async function getPodsOfDeployment(
633+
appsApi: AppsV1Api,
634+
coreApi: CoreV1Api,
635+
deploymentName: string,
636+
namespace: string,
637+
) {
638+
const deployment = await appsApi.readNamespacedDeployment({ name: deploymentName, namespace })
639+
640+
if (!deployment.spec?.selector?.matchLabels) {
641+
throw new Error(`Deployment ${deploymentName} does not have matchLabels`)
642+
}
643+
644+
const labelSelector = Object.entries(deployment.spec.selector.matchLabels)
645+
.map(([key, value]) => `${key}=${value}`)
646+
.join(',')
647+
648+
return await coreApi.listNamespacedPod({
649+
namespace,
650+
labelSelector,
651+
})
652+
}
653+
632654
export async function getPodsOfStatefulSet(
633655
appsApi: AppsV1Api,
634656
statefulSetName: string,

src/common/runtime-upgrades/runtime-upgrades.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { updateDbCollation } from './cloudnative-pg'
66
import { removeOldMinioResources } from './remove-old-minio-resources'
77
import { detectAndRestartOutdatedIstioSidecars } from './restart-istio-sidecars'
88
import { upgradeKnativeServing } from './upgrade-knative-serving-cr'
9-
import { detachApplicationFromApplicationSet, pruneArgoCDImageUpdater } from './v4.13.0'
9+
import { detachApplicationFromApplicationSet, pruneArgoCDImageUpdater, resetGiteaPasswordValidity } from './v4.13.0'
1010
import { removeHttpBinApplication } from './remove-httpbin-application'
1111

1212
export interface RuntimeUpgradeContext {
@@ -151,4 +151,14 @@ export const runtimeUpgrades: RuntimeUpgrades = [
151151
await removeHttpBinApplication()
152152
},
153153
},
154+
{
155+
version: '4.14.0',
156+
applications: {
157+
'gitea-gitea': {
158+
post: async (context: RuntimeUpgradeContext) => {
159+
await resetGiteaPasswordValidity(context)
160+
},
161+
},
162+
},
163+
},
154164
]

src/common/runtime-upgrades/v4.13.0.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ApiException } from '@kubernetes/client-node'
22
import { ARGOCD_APP_PARAMS, ObjectMetadataCollection } from '../constants'
3-
import { getArgoCdApp, k8s, setArgoCdAppSync } from '../k8s'
3+
import { exec, getArgoCdApp, getK8sSecret, getPodsOfDeployment, k8s, setArgoCdAppSync } from '../k8s'
44
import { RuntimeUpgradeContext } from './runtime-upgrades'
55

66
async function scaleDeployment(context: RuntimeUpgradeContext, namespace: string, name: string, replicas: number) {
@@ -135,3 +135,22 @@ export async function detachApplicationFromApplicationSet(context: RuntimeUpgrad
135135
await setArgoCdAppSync('argocd-argocd', true, customApi)
136136
d.log('Cleanup complete: ApplicationSets removed, Applications retained.')
137137
}
138+
139+
export async function resetGiteaPasswordValidity(context: RuntimeUpgradeContext) {
140+
context.debug.info('Resetting status of Gitea admin credentials')
141+
const giteaPods = await getPodsOfDeployment(k8s.app(), k8s.core(), 'gitea', 'gitea')
142+
const [firstPod] = giteaPods.items
143+
// In case Gitea pods happened to be restarting in the meantime, it will likely fix the issue by itself
144+
if (firstPod) {
145+
const giteaCredentialsSecret = await getK8sSecret('gitea-credentials', 'apl-operator')
146+
const userName = giteaCredentialsSecret?.GITEA_USERNAME ?? 'otomi-admin'
147+
const resetCmd = ['gitea', 'admin', 'user', 'must-change-password', '--unset', userName as string]
148+
const { stdout, stderr } = await exec(
149+
firstPod.metadata!.namespace as string,
150+
firstPod.metadata!.name as string,
151+
'gitea',
152+
resetCmd,
153+
)
154+
context.debug.info(stderr, stdout)
155+
}
156+
}

0 commit comments

Comments
 (0)