Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Gitea): add storage size to spec (#509) #510

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions docs/docs/03_crd-reference/gitea.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ spec:
| smtp | [SmtpSpec](./../common/smtp/)? | `null` | |
| resources | [ResourceRequirements](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) | | |
| database | [PostgresDatabaseSpec](./../common/postgres)? | | |
| storage | [StorageSpec](#storagespec)? | | |


### StorageSpec

| Name | Type | Default | |
|------------------|-----------|---------|-----------------------------------------------------------------------------------------------------|
| size | Quantity? | `10Gi` | |
| storageClassName | String? | `null` | An empty value will instruct the system to use the default storage class configured in the cluster. |

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()
}
}
Loading