Skip to content
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY controllers/ controllers/

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

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ KUBECTL := $(TOOLS_BIN_DIR)/kubectl
GOLANGCI_LINT_VERSION := "v1.57.2"
CLUSTERCTL_VERSION := "v1.7.2"

KUSTOMIZE_VER := v4.5.2
KUSTOMIZE_VER := v5.3.0
KUSTOMIZE_BIN := kustomize
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v5
$(KUSTOMIZE): # Build kustomize from tools folder.
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)

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

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

.PHONY: fmt
Expand Down Expand Up @@ -227,15 +226,14 @@ set-manifest-pull-policy:

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build -o bin/manager cmd/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
go run ./cmd/main.go

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
go generate
docker build --load --build-arg BUILDOS=linux --build-arg TARGETARCH=amd64 -t $(CONTROLLER_IMG):$(TAG) .
MANIFEST_IMG=$(CONTROLLER_IMG) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
$(MAKE) set-manifest-pull-policy
Expand Down
14 changes: 13 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: projectsveltos.io
layout:
- go.kubebuilder.io/v3
- go.kubebuilder.io/v4
projectName: jsonnet-controller
repo: github.com/gianlucam76/jsonnet-controller
resources:
Expand All @@ -13,4 +17,12 @@ resources:
kind: JsonnetSource
path: github.com/gianlucam76/jsonnet-controller/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
domain: projectsveltos.io
group: extension
kind: JsonnetSource
path: github.com/gianlucam76/jsonnet-controller/api/v1beta1
version: v1beta1
version: "3"
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ kubectl apply -f https://raw.githubusercontent.com/gianlucam76/jsonnet-controlle
## Using Flux GitRepository

For instance, this Github repository https://github.com/gianlucam76/jsonnet-examples contains jsonnet files.
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.
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.
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.

```yaml
apiVersion: extension.projectsveltos.io/v1alpha1
apiVersion: extension.projectsveltos.io/v1beta1
kind: JsonnetSource
metadata:
name: jsonnetsource-flux
Expand All @@ -45,12 +45,12 @@ spec:
```

```yaml
apiVersion: extension.projectsveltos.io/v1alpha1
apiVersion: extension.projectsveltos.io/v1beta1
kind: JsonnetSource
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"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"}}}
{"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"}}}
creationTimestamp: "2023-05-26T06:55:13Z"
generation: 3
name: jsonnetsource-flux
Expand All @@ -74,15 +74,15 @@ status:
Sveltos can used at this point to deploy resources in managed clusters:

```yaml
apiVersion: config.projectsveltos.io/v1alpha1
apiVersion: config.projectsveltos.io/v1beta1
kind: ClusterProfile
metadata:
name: deploy-resources
spec:
clusterSelector: env=fv
templateResourceRefs:
- resource:
apiVersion: extension.projectsveltos.io/v1alpha1
apiVersion: extension.projectsveltos.io/v1beta1
kind: JsonnetSource
name: jsonnetsource-flux
namespace: default
Expand Down Expand Up @@ -125,7 +125,7 @@ kubectl create configmap jsonnet --from-file=jsonnet.tar.gz=jsonnet.tar.gz
Then we can have JsonnetSource reference this ConfigMap instance

```yaml
apiVersion: extension.projectsveltos.io/v1alpha1
apiVersion: extension.projectsveltos.io/v1beta1
kind: JsonnetSource
metadata:
name: jsonnetsource-configmap
Expand All @@ -141,12 +141,12 @@ spec:
and the controller will programmatically execute jsonnet go module and store the outcome in Status.Results.

```yaml
apiVersion: extension.projectsveltos.io/v1alpha1
apiVersion: extension.projectsveltos.io/v1beta1
kind: JsonnetSource
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"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"}}}
{"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"}}}
creationTimestamp: "2023-05-26T08:28:48Z"
generation: 1
name: jsonnetsource-configmap
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023.
Copyright 2023. projectsveltos.io. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
36 changes: 36 additions & 0 deletions api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023. projectsveltos.io. All rights reserved.

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 v1beta1 contains API Schema definitions for the extension v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=extension.projectsveltos.io
package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "extension.projectsveltos.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
88 changes: 88 additions & 0 deletions api/v1beta1/jsonnetsource_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright 2024. projectsveltos.io. All rights reserved.

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 v1beta1

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

const (
JsonnetSourceKind = "JsonnetSourceKind"
)

// JsonnetSourceSpec defines the desired state of JsonnetSource
type JsonnetSourceSpec struct {
// Namespace of the referenced resource.
// Namespace can be left empty. In such a case, namespace will
// be implicit set to cluster's namespace.
Namespace string `json:"namespace"`

// Name of the rreferenced resource.
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`

// Kind of the resource. Supported kinds are:
// - flux GitRepository;OCIRepository;Bucket
// - ConfigMap/Secret (which will be mounted as volume)
// +kubebuilder:validation:Enum=GitRepository;OCIRepository;Bucket;ConfigMap;Secret
Kind string `json:"kind"`

// Path to the jsonnet file.
// Defaults to 'None', which translates to the root path of the SourceRef.
// +optional
Path string `json:"path,omitempty"`

// Variables contains set of variable to pass to jsonnet
Variables map[string]string `json:"variables,omitempty"`
}

// JsonnetSourceStatus defines the observed state of JsonnetSource
type JsonnetSourceStatus struct {
// Resources contains the output of jsonnet, so the
// resources to be deployed
Resources string `json:"resources,omitempty"`

// FailureMessage provides more information about the error.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
}

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

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

Spec JsonnetSourceSpec `json:"spec,omitempty"`
Status JsonnetSourceStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&JsonnetSource{}, &JsonnetSourceList{})
}
Loading