Skip to content

Commit ad331df

Browse files
authored
Merge pull request #15 from gianlucam76/v1beta1
Move APIs to v1beta1
2 parents 73aae01 + 082b7e2 commit ad331df

28 files changed

+618
-135
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ COPY go.sum go.sum
1313
RUN go mod download
1414

1515
# Copy the go source
16-
COPY main.go main.go
16+
COPY cmd/main.go cmd/main.go
1717
COPY api/ api/
1818
COPY controllers/ controllers/
1919

2020
# Build
21-
RUN CGO_ENABLED=0 GOOS=$BUILDOS GOARCH=$TARGETARCH go build -a -o manager main.go
21+
RUN CGO_ENABLED=0 GOOS=$BUILDOS GOARCH=$TARGETARCH go build -a -o manager cmd/main.go
2222

2323
# Use distroless as minimal base image to package the manager binary
2424
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ KUBECTL := $(TOOLS_BIN_DIR)/kubectl
6969
GOLANGCI_LINT_VERSION := "v1.57.2"
7070
CLUSTERCTL_VERSION := "v1.7.2"
7171

72-
KUSTOMIZE_VER := v4.5.2
72+
KUSTOMIZE_VER := v5.3.0
7373
KUSTOMIZE_BIN := kustomize
7474
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
75-
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4
75+
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5
7676
$(KUSTOMIZE): # Build kustomize from tools folder.
7777
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
7878

@@ -134,7 +134,6 @@ manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) $(ENVSUBST) fmt generate ## Generate W
134134

135135
.PHONY: generate
136136
generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
137-
go generate
138137
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
139138

140139
.PHONY: fmt
@@ -227,15 +226,14 @@ set-manifest-pull-policy:
227226

228227
.PHONY: build
229228
build: generate fmt vet ## Build manager binary.
230-
go build -o bin/manager main.go
229+
go build -o bin/manager cmd/main.go
231230

232231
.PHONY: run
233232
run: manifests generate fmt vet ## Run a controller from your host.
234-
go run ./main.go
233+
go run ./cmd/main.go
235234

236235
.PHONY: docker-build
237236
docker-build: ## Build docker image with the manager.
238-
go generate
239237
docker build --load --build-arg BUILDOS=linux --build-arg TARGETARCH=amd64 -t $(CONTROLLER_IMG):$(TAG) .
240238
MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
241239
$(MAKE) set-manifest-pull-policy

PROJECT

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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
15
domain: projectsveltos.io
26
layout:
3-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
48
projectName: jsonnet-controller
59
repo: github.com/gianlucam76/jsonnet-controller
610
resources:
@@ -13,4 +17,12 @@ resources:
1317
kind: JsonnetSource
1418
path: github.com/gianlucam76/jsonnet-controller/api/v1alpha1
1519
version: v1alpha1
20+
- api:
21+
crdVersion: v1
22+
namespaced: true
23+
domain: projectsveltos.io
24+
group: extension
25+
kind: JsonnetSource
26+
path: github.com/gianlucam76/jsonnet-controller/api/v1beta1
27+
version: v1beta1
1628
version: "3"

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ kubectl apply -f https://raw.githubusercontent.com/gianlucam76/jsonnet-controlle
2525
## Using Flux GitRepository
2626

2727
For instance, this Github repository https://github.com/gianlucam76/jsonnet-examples contains jsonnet files.
28-
You can use Flux to sync from it and then simply post this [JsonnetSource](https://github.com/gianlucam76/jsonnet-controller/blob/main/api/v1alpha1/jsonnetsource_types.go) CRD instance.
28+
You can use Flux to sync from it and then simply post this [JsonnetSource](https://github.com/gianlucam76/jsonnet-controller/blob/main/api/v1beta1/jsonnetsource_types.go) CRD instance.
2929
The jsonnet-controller will detect when Flux has synced the repo (and anytime there is a change), will programatically invoke jsonnet go module and store the outcome in its Status.Resources field.
3030

3131
```yaml
32-
apiVersion: extension.projectsveltos.io/v1alpha1
32+
apiVersion: extension.projectsveltos.io/v1beta1
3333
kind: JsonnetSource
3434
metadata:
3535
name: jsonnetsource-flux
@@ -45,12 +45,12 @@ spec:
4545
```
4646
4747
```yaml
48-
apiVersion: extension.projectsveltos.io/v1alpha1
48+
apiVersion: extension.projectsveltos.io/v1beta1
4949
kind: JsonnetSource
5050
metadata:
5151
annotations:
5252
kubectl.kubernetes.io/last-applied-configuration: |
53-
{"apiVersion":"extension.projectsveltos.io/v1alpha1","kind":"JsonnetSource","metadata":{"annotations":{},"name":"jsonnetsource-flux","namespace":"default"},"spec":{"kind":"GitRepository","name":"flux-system","namespace":"flux-system","path":"./variables/deployment.jsonnet","variables":{"deploymentName":"eng","namespace":"staging","replicas":"3"}}}
53+
{"apiVersion":"extension.projectsveltos.io/v1beta1","kind":"JsonnetSource","metadata":{"annotations":{},"name":"jsonnetsource-flux","namespace":"default"},"spec":{"kind":"GitRepository","name":"flux-system","namespace":"flux-system","path":"./variables/deployment.jsonnet","variables":{"deploymentName":"eng","namespace":"staging","replicas":"3"}}}
5454
creationTimestamp: "2023-05-26T06:55:13Z"
5555
generation: 3
5656
name: jsonnetsource-flux
@@ -74,15 +74,15 @@ status:
7474
Sveltos can used at this point to deploy resources in managed clusters:
7575
7676
```yaml
77-
apiVersion: config.projectsveltos.io/v1alpha1
77+
apiVersion: config.projectsveltos.io/v1beta1
7878
kind: ClusterProfile
7979
metadata:
8080
name: deploy-resources
8181
spec:
8282
clusterSelector: env=fv
8383
templateResourceRefs:
8484
- resource:
85-
apiVersion: extension.projectsveltos.io/v1alpha1
85+
apiVersion: extension.projectsveltos.io/v1beta1
8686
kind: JsonnetSource
8787
name: jsonnetsource-flux
8888
namespace: default
@@ -125,7 +125,7 @@ kubectl create configmap jsonnet --from-file=jsonnet.tar.gz=jsonnet.tar.gz
125125
Then we can have JsonnetSource reference this ConfigMap instance
126126

127127
```yaml
128-
apiVersion: extension.projectsveltos.io/v1alpha1
128+
apiVersion: extension.projectsveltos.io/v1beta1
129129
kind: JsonnetSource
130130
metadata:
131131
name: jsonnetsource-configmap
@@ -141,12 +141,12 @@ spec:
141141
and the controller will programmatically execute jsonnet go module and store the outcome in Status.Results.
142142
143143
```yaml
144-
apiVersion: extension.projectsveltos.io/v1alpha1
144+
apiVersion: extension.projectsveltos.io/v1beta1
145145
kind: JsonnetSource
146146
metadata:
147147
annotations:
148148
kubectl.kubernetes.io/last-applied-configuration: |
149-
{"apiVersion":"extension.projectsveltos.io/v1alpha1","kind":"JsonnetSource","metadata":{"annotations":{},"name":"jsonnetsource-configmap","namespace":"default"},"spec":{"kind":"ConfigMap","name":"jsonnet","namespace":"default","path":"./main.jsonnet","variables":{"namespace":"production"}}}
149+
{"apiVersion":"extension.projectsveltos.io/v1beta1","kind":"JsonnetSource","metadata":{"annotations":{},"name":"jsonnetsource-configmap","namespace":"default"},"spec":{"kind":"ConfigMap","name":"jsonnet","namespace":"default","path":"./main.jsonnet","variables":{"namespace":"production"}}}
150150
creationTimestamp: "2023-05-26T08:28:48Z"
151151
generation: 1
152152
name: jsonnetsource-configmap

api/v1alpha1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023.
2+
Copyright 2023. projectsveltos.io. All rights reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/v1beta1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023. projectsveltos.io. All rights reserved.
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 v1beta1 contains API Schema definitions for the extension v1beta1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=extension.projectsveltos.io
20+
package v1beta1
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: "extension.projectsveltos.io", Version: "v1beta1"}
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/v1beta1/jsonnetsource_types.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Copyright 2024. projectsveltos.io. All rights reserved.
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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
const (
24+
JsonnetSourceKind = "JsonnetSourceKind"
25+
)
26+
27+
// JsonnetSourceSpec defines the desired state of JsonnetSource
28+
type JsonnetSourceSpec struct {
29+
// Namespace of the referenced resource.
30+
// Namespace can be left empty. In such a case, namespace will
31+
// be implicit set to cluster's namespace.
32+
Namespace string `json:"namespace"`
33+
34+
// Name of the rreferenced resource.
35+
// +kubebuilder:validation:MinLength=1
36+
Name string `json:"name"`
37+
38+
// Kind of the resource. Supported kinds are:
39+
// - flux GitRepository;OCIRepository;Bucket
40+
// - ConfigMap/Secret (which will be mounted as volume)
41+
// +kubebuilder:validation:Enum=GitRepository;OCIRepository;Bucket;ConfigMap;Secret
42+
Kind string `json:"kind"`
43+
44+
// Path to the jsonnet file.
45+
// Defaults to 'None', which translates to the root path of the SourceRef.
46+
// +optional
47+
Path string `json:"path,omitempty"`
48+
49+
// Variables contains set of variable to pass to jsonnet
50+
Variables map[string]string `json:"variables,omitempty"`
51+
}
52+
53+
// JsonnetSourceStatus defines the observed state of JsonnetSource
54+
type JsonnetSourceStatus struct {
55+
// Resources contains the output of jsonnet, so the
56+
// resources to be deployed
57+
Resources string `json:"resources,omitempty"`
58+
59+
// FailureMessage provides more information about the error.
60+
// +optional
61+
FailureMessage *string `json:"failureMessage,omitempty"`
62+
}
63+
64+
//+kubebuilder:object:root=true
65+
//+kubebuilder:subresource:status
66+
//+kubebuilder:storageversion
67+
68+
// JsonnetSource is the Schema for the jsonnetsources API
69+
type JsonnetSource struct {
70+
metav1.TypeMeta `json:",inline"`
71+
metav1.ObjectMeta `json:"metadata,omitempty"`
72+
73+
Spec JsonnetSourceSpec `json:"spec,omitempty"`
74+
Status JsonnetSourceStatus `json:"status,omitempty"`
75+
}
76+
77+
//+kubebuilder:object:root=true
78+
79+
// JsonnetSourceList contains a list of JsonnetSource
80+
type JsonnetSourceList struct {
81+
metav1.TypeMeta `json:",inline"`
82+
metav1.ListMeta `json:"metadata,omitempty"`
83+
Items []JsonnetSource `json:"items"`
84+
}
85+
86+
func init() {
87+
SchemeBuilder.Register(&JsonnetSource{}, &JsonnetSourceList{})
88+
}

0 commit comments

Comments
 (0)