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: add docker-compose-runner type #3

Merged
merged 1 commit into from
Feb 10, 2023
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ kubebuilder init --domain 6zacode-toolbox.github.io --license apache2 --owner "6

kubebuilder create api --group tool --version v1 --kind DockerHost --controller --resource

kubebuilder create api --group tool --version v1 --kind DockerComposeRunner --controller --resource

make manifests
# When doing complex objects start by parts, as serilziation may be tricky

Expand Down
22 changes: 21 additions & 1 deletion explore/dockerhost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ docker ps -a --format "{{json .}}" | jq -s
# Translation

https://www.json2yaml.com/
https://mholt.github.io/json-to-go/
https://mholt.github.io/json-to-go/

```json
{"hostIp": "192.168.1.2",
"composeFile": "docker-compose-app.yaml",
"executionPath": "/my/app",
"repoAddress": "https://github.com/6zacode-toolbox/docker-agent.git",
"mountVars":["ENV-1", "ENV-2"]}
```

```golang


type AutoGenerated struct {
HostIP string `json:"hostIp"`
ComposeFile string `json:"composeFile"`
ExecutionPath string `json:"executionPath"`
RepoAddress string `json:"repoAddress"`
MountVars []string `json:"mountVars"`
}
```
9 changes: 9 additions & 0 deletions operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ resources:
kind: DockerHost
path: github.com/6zacode-toolbox/docker-operator/operator/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: 6zacode-toolbox.github.io
group: tool
kind: DockerComposeRunner
path: github.com/6zacode-toolbox/docker-operator/operator/api/v1
version: v1
version: "3"
69 changes: 69 additions & 0 deletions operator/api/v1/dockercomposerunner_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2023 6zacode-toolbox.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// DockerComposeRunnerSpec defines the desired state of DockerComposeRunner
type DockerComposeRunnerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of DockerComposeRunner. Edit dockercomposerunner_types.go to remove/update
HostIP string `json:"hostip"`
ComposeFile string `json:"composeFile"`
ExecutionPath string `json:"executionPath,omitempty"`
RepoAddress string `json:"repoAddress"`
MountVars []string `json:"mountVars,omitempty"`
}

// DockerComposeRunnerStatus defines the observed state of DockerComposeRunner
type DockerComposeRunnerStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Instanced bool `json:"instanced,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// DockerComposeRunner is the Schema for the dockercomposerunners API
type DockerComposeRunner struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DockerComposeRunnerSpec `json:"spec,omitempty"`
Status DockerComposeRunnerStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// DockerComposeRunnerList contains a list of DockerComposeRunner
type DockerComposeRunnerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DockerComposeRunner `json:"items"`
}

func init() {
SchemeBuilder.Register(&DockerComposeRunner{}, &DockerComposeRunnerList{})
}
94 changes: 94 additions & 0 deletions operator/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.1
creationTimestamp: null
name: dockercomposerunners.tool.6zacode-toolbox.github.io
spec:
group: tool.6zacode-toolbox.github.io
names:
kind: DockerComposeRunner
listKind: DockerComposeRunnerList
plural: dockercomposerunners
singular: dockercomposerunner
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: DockerComposeRunner is the Schema for the dockercomposerunners
API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: DockerComposeRunnerSpec defines the desired state of DockerComposeRunner
properties:
composeFile:
type: string
executionPath:
type: string
hostip:
description: Foo is an example field of DockerComposeRunner. Edit
dockercomposerunner_types.go to remove/update
type: string
mountVars:
items:
type: string
type: array
repoAddress:
type: string
required:
- composeFile
- hostip
- repoAddress
type: object
status:
description: DockerComposeRunnerStatus defines the observed state of DockerComposeRunner
properties:
instanced:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
type: boolean
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions operator/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# It should be run by config/default
resources:
- bases/tool.6zacode-toolbox.github.io_dockerhosts.yaml
- bases/tool.6zacode-toolbox.github.io_dockercomposerunners.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_dockerhosts.yaml
#- patches/webhook_in_dockercomposerunners.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_dockerhosts.yaml
#- patches/cainjection_in_dockercomposerunners.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: dockercomposerunners.tool.6zacode-toolbox.github.io
16 changes: 16 additions & 0 deletions operator/config/crd/patches/webhook_in_dockercomposerunners.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: dockercomposerunners.tool.6zacode-toolbox.github.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
31 changes: 31 additions & 0 deletions operator/config/rbac/dockercomposerunner_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# permissions for end users to edit dockercomposerunners.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: dockercomposerunner-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: operator
app.kubernetes.io/part-of: operator
app.kubernetes.io/managed-by: kustomize
name: dockercomposerunner-editor-role
rules:
- apiGroups:
- tool.6zacode-toolbox.github.io
resources:
- dockercomposerunners
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- tool.6zacode-toolbox.github.io
resources:
- dockercomposerunners/status
verbs:
- get
27 changes: 27 additions & 0 deletions operator/config/rbac/dockercomposerunner_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to view dockercomposerunners.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: dockercomposerunner-viewer-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: operator
app.kubernetes.io/part-of: operator
app.kubernetes.io/managed-by: kustomize
name: dockercomposerunner-viewer-role
rules:
- apiGroups:
- tool.6zacode-toolbox.github.io
resources:
- dockercomposerunners
verbs:
- get
- list
- watch
- apiGroups:
- tool.6zacode-toolbox.github.io
resources:
- dockercomposerunners/status
verbs:
- get
Loading