Skip to content

Commit

Permalink
feat(Gitea): add storage size to spec (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmoz committed Jan 25, 2024
1 parent 0abbb8d commit a3bb0d3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
10 changes: 10 additions & 0 deletions deploy/crd/giteas.glasskube.eu-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ spec:
type: boolean
sshHost:
type: string
storage:
properties:
size:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
storageClassName:
type: string
type: object
version:
pattern: \d+\.\d+\.\d+
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ data class GiteaSpec(
val version: String = "1.20.4",
@field:Nullable
override val database: PostgresDatabaseSpec = PostgresDatabaseSpec(),
override val backups: BackupSpec?
) : HasBackupSpec, HasDatabaseSpec<PostgresDatabaseSpec>
override val backups: BackupSpec?,
val storage: StorageSpec?
) : HasBackupSpec, HasDatabaseSpec<PostgresDatabaseSpec> {
data class StorageSpec(
val size: Quantity?,
val storageClassName: String?
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import eu.glasskube.kubernetes.api.model.metadata
import eu.glasskube.kubernetes.api.model.persistentVolumeClaim
import eu.glasskube.kubernetes.api.model.resources
import eu.glasskube.kubernetes.api.model.spec
import eu.glasskube.operator.api.reconciler.getSecondaryResource
import eu.glasskube.operator.apps.gitea.Gitea
import eu.glasskube.operator.apps.gitea.GiteaReconciler
import eu.glasskube.operator.apps.gitea.genericResourceName
import eu.glasskube.operator.apps.gitea.resourceLabels
import eu.glasskube.utils.logger
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim
import io.fabric8.kubernetes.api.model.Quantity
import io.javaoperatorsdk.operator.api.reconciler.Context
Expand All @@ -26,10 +28,31 @@ class GiteaVolume : CRUDKubernetesDependentResource<PersistentVolumeClaim, Gitea
spec {
resources {
requests = mapOf(
"storage" to Quantity("10", "Gi")
"storage" to (primary.spec.storage?.size ?: Quantity("10", "Gi"))
)
}
storageClassName = primary.spec.storage?.storageClassName
accessModes = listOf("ReadWriteMany")
}
}

override fun onUpdated(
primary: Gitea,
updated: PersistentVolumeClaim,
actual: PersistentVolumeClaim,
context: Context<Gitea>
) {
super.onUpdated(primary, updated, actual, context)
if (updated.spec.resources.requests != actual.spec.resources.requests) {
context.getSecondaryResource(GiteaDeployment.Discriminator()).ifPresent {
log.info("Restarting deployment after PVC resize")
Thread.sleep(1000)
context.client.apps().deployments().resource(it).rolling().restart()
}
}
}

companion object {
private val log = logger()
}
}

0 comments on commit a3bb0d3

Please sign in to comment.