Skip to content

Commit b841f73

Browse files
authored
add lua script support (#106)
* add lua script support * fix unit test * change lua function name * change lua function name * change to CustomHealth
1 parent 70e715f commit b841f73

29 files changed

Lines changed: 1124 additions & 18 deletions

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/

Makefile

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ IMG ?= deployment-agent:latest
99

1010
ENVTEST ?= $(shell which setup-envtest)
1111

12+
## Location to install dependencies to
13+
LOCALBIN ?= $(shell pwd)/bin
14+
$(LOCALBIN):
15+
mkdir -p $(LOCALBIN)
16+
1217
ENVTEST_K8S_VERSION := 1.28.3
18+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
1319

1420
include tools.mk
1521

@@ -22,9 +28,22 @@ PRE = --ensure
2228
##@ General
2329

2430
.PHONY: help
25-
help: ## show help
31+
help: ## Display this help.
2632
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
2733

34+
controller-gen: ## Download controller-gen locally if necessary.
35+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.3)
36+
37+
##@ Development
38+
39+
.PHONY: manifests
40+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
41+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
42+
43+
.PHONY: generate
44+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
45+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
46+
2847
##@ Run
2948

3049
.PHONY: run
@@ -86,3 +105,17 @@ envtest: --tool ## Download and install setup-envtest in the $GOPATH/bin
86105
.PHONY: mockery
87106
mockery: TOOL = mockery
88107
mockery: --tool
108+
109+
# go-get-tool will 'go get' any package $2 and install it to $1.
110+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
111+
define go-get-tool
112+
@[ -f $(1) ] || { \
113+
set -e ;\
114+
TMP_DIR=$$(mktemp -d) ;\
115+
cd $$TMP_DIR ;\
116+
go mod init tmp ;\
117+
echo "Downloading $(2)" ;\
118+
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
119+
rm -rf $$TMP_DIR ;\
120+
}
121+
endef

PROJECT

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
domain: plural.sh
6+
layout:
7+
- go.kubebuilder.io/v4
8+
projectName: kubebilder
9+
repo: github.com/pluralsh/deployment-operator
10+
resources:
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
controller: true
15+
domain: plural.sh
16+
group: deployments
17+
kind: CustomHealth
18+
path: github.com/pluralsh/deployment-operator/api/v1alpha1
19+
version: v1alpha1
20+
version: "3"

api/v1alpha1/common_types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package v1alpha1
2+
3+
type ConditionType string
4+
5+
func (c ConditionType) String() string {
6+
return string(c)
7+
}
8+
9+
const (
10+
ReadyConditionType ConditionType = "Ready"
11+
)
12+
13+
type ConditionReason string
14+
15+
func (c ConditionReason) String() string {
16+
return string(c)
17+
}
18+
19+
const (
20+
ReadyConditionReason ConditionReason = "Ready"
21+
)
22+
23+
type ConditionMessage string
24+
25+
func (c ConditionMessage) String() string {
26+
return string(c)
27+
}

api/v1alpha1/customhealth_types.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/api/meta"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// CustomHealthSpec defines the desired state of CustomHealth
25+
type CustomHealthSpec struct {
26+
Script string `json:"script,omitempty"`
27+
}
28+
29+
// CustomHealthStatus defines the observed state of CustomHealth
30+
type CustomHealthStatus struct {
31+
// Represents the observations of a HealthConvert current state.
32+
// +patchMergeKey=type
33+
// +patchStrategy=merge
34+
// +listType=map
35+
// +listMapKey=type
36+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
37+
}
38+
39+
//+kubebuilder:object:root=true
40+
//+kubebuilder:subresource:status
41+
42+
// CustomHealth is the Schema for the HealthConverts API
43+
type CustomHealth struct {
44+
metav1.TypeMeta `json:",inline"`
45+
metav1.ObjectMeta `json:"metadata,omitempty"`
46+
47+
Spec CustomHealthSpec `json:"spec,omitempty"`
48+
Status CustomHealthStatus `json:"status,omitempty"`
49+
}
50+
51+
//+kubebuilder:object:root=true
52+
53+
// CustomHealthList contains a list of CustomHealth
54+
type CustomHealthList struct {
55+
metav1.TypeMeta `json:",inline"`
56+
metav1.ListMeta `json:"metadata,omitempty"`
57+
Items []CustomHealth `json:"items"`
58+
}
59+
60+
func init() {
61+
SchemeBuilder.Register(&CustomHealth{}, &CustomHealthList{})
62+
}
63+
64+
func (c *CustomHealth) SetCondition(condition metav1.Condition) {
65+
meta.SetStatusCondition(&c.Status.Conditions, condition)
66+
}

api/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the deployments v1alpha1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=deployments.plural.sh
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "deployments.plural.sh", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)