Skip to content

Commit

Permalink
Drop apiextensions (#180)
Browse files Browse the repository at this point in the history
* drop apiextensions

* remove unused

* add changelog

* use released apiextensions-application

* replace jwt-go

* replace etcd
  • Loading branch information
tfussell authored Nov 29, 2021
1 parent 7f2777f commit 30342ee
Show file tree
Hide file tree
Showing 26 changed files with 1,702 additions and 407 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Drop `apiextensions` dependency.

## [0.4.0] - 2021-08-09

## [0.3.3] - 2021-08-05
Expand Down
72 changes: 72 additions & 0 deletions Makefile.custom.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Directories.
API_DIR := api
CRD_DIR := config/crd
SCRIPTS_DIR := hack
TOOLS_DIR := $(SCRIPTS_DIR)/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)

# Binaries.
# Need to use abspath so we can invoke these from subdirectories
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)

BUILD_COLOR = ""
GEN_COLOR = ""
NO_COLOR = ""

ifneq (, $(shell command -v tput))
ifeq ($(shell test `tput colors` -ge 8 && echo "yes"), yes)
BUILD_COLOR = \033[0;34m
GEN_COLOR = \033[0;32m
NO_COLOR = \033[0m
endif
endif

DEEPCOPY_BASE = zz_generated.deepcopy
MODULE = $(shell go list -m)
BOILERPLATE = $(SCRIPTS_DIR)/boilerplate.go.txt
YEAR = $(shell date +'%Y')

DEEPCOPY_FILES := $(shell find $(API_DIR) -name $(DEEPCOPY_BASE).go)

all: generate

$(CONTROLLER_GEN): $(TOOLS_DIR)/controller-gen/go.mod
@echo "$(BUILD_COLOR)Building controller-gen$(NO_COLOR)"
cd $(TOOLS_DIR)/controller-gen \
&& go build -tags=tools -o $(CONTROLLER_GEN) sigs.k8s.io/controller-tools/cmd/controller-gen

.PHONY: generate
generate:
@$(MAKE) generate-deepcopy
@$(MAKE) generate-manifests

.PHONY: verify
verify:
@$(MAKE) clean-generated
@$(MAKE) generate
git diff --exit-code

.PHONY: generate-deepcopy
generate-deepcopy: $(CONTROLLER_GEN)
@echo "$(GEN_COLOR)Generating deepcopy$(NO_COLOR)"
$(CONTROLLER_GEN) \
object:headerFile=$(BOILERPLATE),year=$(YEAR) \
paths=./$(API_DIR)/...

.PHONY: generate-manifests
generate-manifests: $(CONTROLLER_GEN)
@echo "$(GEN_COLOR)Generating CRDs$(NO_COLOR)"
$(CONTROLLER_GEN) \
crd \
paths=./$(API_DIR)/... \
output:dir="./$(CRD_DIR)"

.PHONY: clean-generated
clean-generated:
@echo "$(GEN_COLOR)Cleaning generated files$(NO_COLOR)"
rm -rf $(CRD_DIR) $(DEEPCOPY_FILES)

.PHONY: clean-tools
clean-tools:
@echo "$(GEN_COLOR)Cleaning tools$(NO_COLOR)"
rm -rf $(TOOLS_BIN_DIR)
97 changes: 97 additions & 0 deletions api/v1alpha1/config_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package v1alpha1

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

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:resource:categories=common;config;giantswarm
// +k8s:openapi-gen=true

// Config represents configuration of an App.
type Config struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ConfigSpec `json:"spec"`
// +kubebuilder:validation:Optional
// Status part of the Config resource.
Status ConfigStatus `json:"status,omitempty"`
}

// ConfigSpec is the spec part for the Config resource.
// +k8s:openapi-gen=true
type ConfigSpec struct {
// App details for which the configuration should be generated.
App ConfigSpecApp `json:"app"`
}

// ConfigSpecApp holds the information about the App to be configured.
// +k8s:openapi-gen=true
type ConfigSpecApp struct {
// Name is the name of the App.
Name string `json:"name"`
// Version is the version of the App.
Version string `json:"version"`
// Catalog is the name of the App's App Catalog.
Catalog string `json:"catalog"`
}

// ConfigStatus holds status information about the generated configuration.
// +k8s:openapi-gen=true
type ConfigStatus struct {
// +kubebuilder:validation:Optional
// App details for which the configuration was generated.
App ConfigStatusApp `json:"app,omitempty"`
// +kubebuilder:validation:Optional
// Config holds the references to the generated configuration.
Config ConfigStatusConfig `json:"config,omitempty"`
// +kubebuilder:validation:Optional
// Version of the giantswarm/config repository used to generate the
// configuration.
Version string `json:"version,omitempty"`
}

// ConfigStatusApp holds the information about the App used to generate
// referenced configuration.
// +k8s:openapi-gen=true
type ConfigStatusApp struct {
// Name is the name of the App.
Name string `json:"name"`
// Version is the version of the App.
Version string `json:"version"`
// Catalog is the name of the App's App Catalog.
Catalog string `json:"catalog"`
}

// ConfigStatusConfig holds configuration ConfigMap and Secret references to be
// used to configure the App.
// +k8s:openapi-gen=true
type ConfigStatusConfig struct {
ConfigMapRef ConfigStatusConfigConfigMapRef `json:"configMapRef"`
SecretRef ConfigStatusConfigSecretRef `json:"secretRef"`
}

// ConfigStatusConfigConfigMapRef contains a reference to the generated ConfigMap.
// +k8s:openapi-gen=true
type ConfigStatusConfigConfigMapRef struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
}

// ConfigStatusConfigSecretRef contains a reference to the generated Secret.
// +k8s:openapi-gen=true
type ConfigStatusConfigSecretRef struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type ConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Config `json:"items"`
}
9 changes: 9 additions & 0 deletions api/v1alpha1/config_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1alpha1

import "testing"

func Test_Config_Spec_Status_App(t *testing.T) {
t.Log("ensure ConfigSpecApp ConfigStatusApp have identical fields")
specApp := ConfigSpecApp{}
_ = ConfigStatusApp(specApp)
}
5 changes: 5 additions & 0 deletions api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register

// +groupName=core.giantswarm.io
package v1alpha1
40 changes: 40 additions & 0 deletions api/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v1alpha1

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

const (
group = "core.giantswarm.io"
version = "v1alpha1"
)

// knownTypes is the full list of objects to register with the scheme. It
// should contain all zero values of custom objects and custom object lists
// in the group version.
var knownTypes = []runtime.Object{
&Config{},
&ConfigList{},
}

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{
Group: group,
Version: version,
}

var (
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)

// AddToScheme is used by the generated client.
AddToScheme = schemeBuilder.AddToScheme
)

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion, knownTypes...)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
Loading

0 comments on commit 30342ee

Please sign in to comment.