Skip to content

Commit

Permalink
feat(package-operator): add fields to package info crd and manifest s…
Browse files Browse the repository at this point in the history
…chema
  • Loading branch information
kosmoz committed Jan 16, 2024
1 parent 1798d9d commit 5b78e1f
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 17 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ endif
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker

OUT_DIR ?= $(shell pwd)/dist

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down Expand Up @@ -44,6 +46,10 @@ help: ## Display this help.

##@ Development

.PHONY: schema-gen
schema-gen: # Generate a schema.json file for the package manifest type.
go run ./internal/cmd/schema-gen -o schema

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
Expand Down Expand Up @@ -83,15 +89,15 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o dist/package-operator ./cmd/package-operator/main.go
build: manifests generate schema-gen fmt vet ## Build manager binary.
go build -o $(OUT_DIR)/package-operator ./cmd/package-operator/main.go

.PHONY: build-cli
build-cli: fmt vet ## Build cli binary.
go build -o dist/glasskube ./cmd/glasskube/main.go
go build -o $(OUT_DIR)/glasskube ./cmd/glasskube/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
run: manifests generate schema-gen fmt vet ## Run a controller from your host.
go run ./cmd/package-operator/main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
Expand Down
73 changes: 73 additions & 0 deletions api/v1alpha1/package_manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2024.
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 v1alpha1

import (
"github.com/invopop/jsonschema"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

// JSON wraps the apiextensionsv1.JSON type so we can create a custom JSONSchema function
type JSON struct {
apiextensionsv1.JSON `json:"-"`
}

func (JSON) JSONSchema() *jsonschema.Schema {
return &jsonschema.Schema{
Type: "object",
AdditionalProperties: jsonschema.TrueSchema,
}
}

type HelmManifest struct {
// RepositoryUrl is the remote URL of the helm repository. This is the same URL you would use
// if you use "helm repo add ...".
RepositoryUrl string `json:"repositoryUrl" jsonschema:"required"`
// ChartName is the name of the chart that represents this package.
ChartName string `json:"chartName" jsonschema:"required"`
// ChartVersion of the chart that should be installed.
ChartVersion string `json:"chartVersion" jsonschema:"required"`
// Values that should be used for the helm release
Values JSON `json:"values,omitempty"`
}

type KustomizeManifest struct {
}

// PackageEntrypoint defines a service port a user may use to access the package
type PackageEntrypoint struct {
// Name of this entrypoint. Used for "glasskube open [package-name] [entypoint-name]" if more
// than one entrypoint exists. Optional if the package only has one entrypoint.
Name string `json:"name,omitempty"`
// ServiceName is the name of a service that is part of
ServiceName string `json:"serviceName" jsonschema:"required"`
// Port of the service to bind to
Port int32 `json:"port" jsonschema:"required"`
}

type PackageManifest struct {
Name string `json:"name" jsonschema:"required"`
ShortDescription string `json:"shortDescription,omitempty"`
IconUrl string `json:"iconUrl,omitempty"`
// Helm instructs the controller to create a helm release when installing this package.
Helm HelmManifest `json:"helm,omitempty"`
// Kustomize instructs the controller to apply a kustomization when installing this package [PLACEHOLDER].
Kustomize KustomizeManifest `json:"kustomize,omitempty"`
// DefaultNamespace to install the package. May be overridden.
DefaultNamespace string `json:"defaultNamespace,omitempty" jsonschema:"required"`
Entrypoints []PackageEntrypoint `json:"entrypoints,omitempty"`
}
11 changes: 4 additions & 7 deletions api/v1alpha1/packageinfo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ import (

// PackageInfoSpec defines the desired state of PackageInfo
type PackageInfoSpec 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 PackageInfo. Edit packageinfo_types.go to remove/update
Foo string `json:"foo,omitempty"`
Name string `json:"name,omitempty"`
RepositoryUrl string `json:"repositoryUrl,omitempty"`
}

// PackageInfoStatus defines the observed state of PackageInfo
type PackageInfoStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Manifest PackageManifest `json:"manifest,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

//+kubebuilder:object:root=true
Expand Down
120 changes: 118 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 5b78e1f

Please sign in to comment.