-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Gitea): add support for actions [WIP]
- Loading branch information
Showing
17 changed files
with
429 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Fabric8 CRDGenerator, manual edits might get overwritten! | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: giteaactionrunners.glasskube.eu | ||
spec: | ||
group: glasskube.eu | ||
names: | ||
kind: GiteaActionRunner | ||
plural: giteaactionrunners | ||
singular: giteaactionrunner | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
properties: | ||
spec: | ||
properties: | ||
token: | ||
type: string | ||
gitea: | ||
properties: | ||
name: | ||
type: string | ||
type: object | ||
required: | ||
- token | ||
- gitea | ||
type: object | ||
status: | ||
properties: | ||
ready: | ||
type: boolean | ||
type: object | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: | ||
status: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...main/kotlin/eu/glasskube/kubernetes/api/model/apps/RollingUpdateStatefulSetStrategyDsl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
operator/src/main/kotlin/eu/glasskube/operator/apps/gitea/GiteaActionRunnerSpecTemplate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package eu.glasskube.operator.apps.gitea | ||
|
||
import io.fabric8.generator.annotation.Required | ||
|
||
data class GiteaActionRunnerSpecTemplate( | ||
@field:Required | ||
val token: String | ||
) | ||
|
||
val GiteaActionRunnerSpecTemplate.tokenHash: String | ||
get() = (token.hashCode().toLong() + Int.MAX_VALUE).toString(16) |
6 changes: 6 additions & 0 deletions
6
operator/src/main/kotlin/eu/glasskube/operator/apps/gitea/GiteaActionsSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package eu.glasskube.operator.apps.gitea | ||
|
||
data class GiteaActionsSpec( | ||
val enabled: Boolean = false, | ||
val runners: List<GiteaActionRunnerSpecTemplate> = emptyList() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
operator/src/main/kotlin/eu/glasskube/operator/apps/gitea/dependent/GiteaActionRunners.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package eu.glasskube.operator.apps.gitea.dependent | ||
|
||
import eu.glasskube.kubernetes.api.model.metadata | ||
import eu.glasskube.kubernetes.api.model.namespace | ||
import eu.glasskube.operator.apps.gitea.Gitea | ||
import eu.glasskube.operator.apps.gitea.GiteaActionRunnerSpecTemplate | ||
import eu.glasskube.operator.apps.gitea.GiteaReconciler | ||
import eu.glasskube.operator.apps.gitea.resourceLabels | ||
import eu.glasskube.operator.apps.gitea.runner.GiteaActionRunner | ||
import eu.glasskube.operator.apps.gitea.runner.GiteaActionRunnerSpec | ||
import eu.glasskube.operator.apps.gitea.runner.giteaActionRunner | ||
import eu.glasskube.operator.apps.gitea.tokenHash | ||
import io.fabric8.kubernetes.api.model.LocalObjectReference | ||
import io.javaoperatorsdk.operator.api.reconciler.Context | ||
import io.javaoperatorsdk.operator.processing.dependent.BulkDependentResource | ||
import io.javaoperatorsdk.operator.processing.dependent.Matcher | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent | ||
|
||
@KubernetesDependent(labelSelector = GiteaReconciler.SELECTOR) | ||
class GiteaActionRunners : | ||
CRUDKubernetesDependentResource<GiteaActionRunner, Gitea>(GiteaActionRunner::class.java), | ||
BulkDependentResource<GiteaActionRunner, Gitea> { | ||
|
||
fun desired(primary: Gitea, template: GiteaActionRunnerSpecTemplate) = giteaActionRunner { | ||
metadata { | ||
name("${primary.metadata.name}-${template.tokenHash}") | ||
namespace(primary.namespace) | ||
labels(primary.resourceLabels) | ||
} | ||
spec = GiteaActionRunnerSpec( | ||
template.token, | ||
LocalObjectReference(primary.metadata.name) | ||
) | ||
} | ||
|
||
override fun desiredResources(primary: Gitea, context: Context<Gitea>) = primary.spec.actions.run { | ||
if (enabled) { | ||
runners.map { desired(primary, it) }.associateBy { it.metadata.name } | ||
} else { | ||
emptyMap() | ||
} | ||
} | ||
|
||
override fun getSecondaryResources(primary: Gitea, context: Context<Gitea>) = | ||
context.getSecondaryResources(GiteaActionRunner::class.java) | ||
.filter { it.spec.gitea.name == primary.metadata.name } | ||
.associateBy { it.metadata.name } | ||
|
||
override fun match( | ||
actualResource: GiteaActionRunner, | ||
desired: GiteaActionRunner, | ||
primary: Gitea, | ||
context: Context<Gitea> | ||
): Matcher.Result<GiteaActionRunner> = | ||
super<CRUDKubernetesDependentResource>.match(actualResource, desired, primary, context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
operator/src/main/kotlin/eu/glasskube/operator/apps/gitea/runner/GiteaActionRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package eu.glasskube.operator.apps.gitea.runner | ||
|
||
import eu.glasskube.operator.Labels | ||
import eu.glasskube.operator.apps.gitea.Gitea | ||
import io.fabric8.kubernetes.api.model.Namespaced | ||
import io.fabric8.kubernetes.client.CustomResource | ||
import io.fabric8.kubernetes.model.annotation.Group | ||
import io.fabric8.kubernetes.model.annotation.Version | ||
|
||
@Group("glasskube.eu") | ||
@Version("v1alpha1") | ||
class GiteaActionRunner : CustomResource<GiteaActionRunnerSpec, GiteaActionRunnerStatus>(), Namespaced { | ||
companion object { | ||
internal const val APP_NAME = "act-runner" | ||
internal const val APP_VERSION = "0.2.6" | ||
internal const val APP_IMAGE = "${Gitea.APP_NAME}/act_runner:$APP_VERSION" | ||
internal const val DOCKER_IMAGE = "docker:23.0.6-dind" | ||
} | ||
} | ||
|
||
fun giteaActionRunner(block: GiteaActionRunner.() -> Unit) = GiteaActionRunner().apply(block) | ||
|
||
internal val GiteaActionRunner.resourceLabels | ||
get() = Labels.resourceLabels( | ||
GiteaActionRunner.APP_NAME, | ||
metadata.name, | ||
Gitea.APP_NAME, | ||
GiteaActionRunner.APP_VERSION, | ||
GiteaActionRunner.APP_NAME | ||
) | ||
internal val GiteaActionRunner.resourceLabelSelector | ||
get() = Labels.resourceLabelSelector(GiteaActionRunner.APP_NAME, metadata.name, Gitea.APP_NAME) | ||
internal val GiteaActionRunner.genericResourceName get() = "${GiteaActionRunner.APP_NAME}-${metadata.name}" | ||
internal val GiteaActionRunner.secretName get() = "$genericResourceName-token" |
36 changes: 36 additions & 0 deletions
36
...or/src/main/kotlin/eu/glasskube/operator/apps/gitea/runner/GiteaActionRunnerReconciler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package eu.glasskube.operator.apps.gitea.runner | ||
|
||
import eu.glasskube.kubernetes.client.patchOrUpdateStatus | ||
import eu.glasskube.operator.Labels | ||
import eu.glasskube.operator.api.reconciler.getSecondaryResource | ||
import eu.glasskube.operator.apps.gitea.Gitea | ||
import eu.glasskube.operator.apps.gitea.runner.dependent.GiteaActionRunnerSecret | ||
import eu.glasskube.operator.apps.gitea.runner.dependent.GiteaActionRunnerStatefulSet | ||
import eu.glasskube.operator.generic.condition.isReady | ||
import io.fabric8.kubernetes.api.model.apps.StatefulSet | ||
import io.javaoperatorsdk.operator.api.reconciler.Context | ||
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration | ||
import io.javaoperatorsdk.operator.api.reconciler.Reconciler | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent | ||
import kotlin.jvm.optionals.getOrDefault | ||
|
||
@ControllerConfiguration( | ||
dependents = [ | ||
Dependent(type = GiteaActionRunnerStatefulSet::class), | ||
Dependent(type = GiteaActionRunnerSecret::class) | ||
] | ||
) | ||
class GiteaActionRunnerReconciler : Reconciler<GiteaActionRunner> { | ||
override fun reconcile(resource: GiteaActionRunner, context: Context<GiteaActionRunner>) = with(context) { | ||
resource.patchOrUpdateStatus( | ||
GiteaActionRunnerStatus( | ||
getSecondaryResource<StatefulSet>().map { it.isReady }.getOrDefault(false) | ||
) | ||
) | ||
} | ||
|
||
companion object { | ||
internal const val SELECTOR = | ||
"${Labels.MANAGED_BY_GLASSKUBE},${Labels.PART_OF}=${Gitea.APP_NAME},${Labels.NAME}=${GiteaActionRunner.APP_NAME}" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
operator/src/main/kotlin/eu/glasskube/operator/apps/gitea/runner/GiteaActionRunnerSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package eu.glasskube.operator.apps.gitea.runner | ||
|
||
import io.fabric8.generator.annotation.Required | ||
import io.fabric8.kubernetes.api.model.LocalObjectReference | ||
|
||
data class GiteaActionRunnerSpec( | ||
@field:Required | ||
val token: String, | ||
@field:Required | ||
val gitea: LocalObjectReference | ||
) |
5 changes: 5 additions & 0 deletions
5
operator/src/main/kotlin/eu/glasskube/operator/apps/gitea/runner/GiteaActionRunnerStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package eu.glasskube.operator.apps.gitea.runner | ||
|
||
data class GiteaActionRunnerStatus( | ||
val ready: Boolean | ||
) |
26 changes: 26 additions & 0 deletions
26
.../main/kotlin/eu/glasskube/operator/apps/gitea/runner/dependent/GiteaActionRunnerSecret.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package eu.glasskube.operator.apps.gitea.runner.dependent | ||
|
||
import eu.glasskube.kubernetes.api.model.metadata | ||
import eu.glasskube.kubernetes.api.model.namespace | ||
import eu.glasskube.kubernetes.api.model.secret | ||
import eu.glasskube.operator.apps.gitea.runner.GiteaActionRunner | ||
import eu.glasskube.operator.apps.gitea.runner.GiteaActionRunnerReconciler | ||
import eu.glasskube.operator.apps.gitea.runner.resourceLabels | ||
import eu.glasskube.operator.apps.gitea.runner.secretName | ||
import eu.glasskube.utils.encodeBase64 | ||
import io.fabric8.kubernetes.api.model.Secret | ||
import io.javaoperatorsdk.operator.api.reconciler.Context | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource | ||
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent | ||
|
||
@KubernetesDependent(labelSelector = GiteaActionRunnerReconciler.SELECTOR) | ||
class GiteaActionRunnerSecret : CRUDKubernetesDependentResource<Secret, GiteaActionRunner>(Secret::class.java) { | ||
override fun desired(primary: GiteaActionRunner, context: Context<GiteaActionRunner>) = secret { | ||
metadata { | ||
name(primary.secretName) | ||
namespace(primary.namespace) | ||
labels(primary.resourceLabels) | ||
} | ||
data = mapOf("GITEA_RUNNER_REGISTRATION_TOKEN" to primary.spec.token.encodeBase64()) | ||
} | ||
} |
Oops, something went wrong.