Skip to content

Commit

Permalink
implement providerConfig parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
phyrog committed Oct 11, 2024
1 parent a48c7bf commit 5ae6089
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 11 deletions.
10 changes: 10 additions & 0 deletions cmd/gardener-extension-shoot-kubecost/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
extensionscontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/util"
"github.com/gardener/gardener/pkg/logger"
apisconfig "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis/config"
"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis/config/v1alpha1"
"github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/controller/lifecycle"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -82,6 +84,14 @@ func (o *Options) run(ctx context.Context) error {
return fmt.Errorf("could not update manager scheme: %s", err)
}

if err := apisconfig.AddToScheme(mgr.GetScheme()); err != nil {
return fmt.Errorf("could not update manager scheme: %s", err)
}

if err := v1alpha1.AddToScheme(mgr.GetScheme()); err != nil {
return fmt.Errorf("could not update manager scheme: %s", err)
}

o.controllerOptions.Completed().Apply(&lifecycle.DefaultAddOptions.ControllerOptions)
o.lifecycleOptions.Completed().Apply(&lifecycle.DefaultAddOptions.ControllerOptions)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ replace k8s.io/code-generator => k8s.io/code-generator v0.29.9
require (
carvel.dev/ytt v0.50.0
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0
github.com/andybalholm/brotli v1.1.0
github.com/gardener/gardener v1.104.0
github.com/go-logr/logr v1.4.2
github.com/spf13/cobra v1.8.1
Expand All @@ -24,7 +25,6 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
Expand Down
1 change: 1 addition & 0 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// bla
31 changes: 31 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Copyright 2017 The Kubernetes Authors.
#
# 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.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

bash "${CODEGEN_PKG}/generate-internal-groups.sh" \
deepcopy,defaulter,conversion \
github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis \
github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis \
github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis \
"config:v1alpha1" \
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
--output-base "$HOME/Projects"
6 changes: 4 additions & 2 deletions kubecost/kubecost.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
yttui "carvel.dev/ytt/pkg/cmd/ui"
yttfiles "carvel.dev/ytt/pkg/files"
"github.com/andybalholm/brotli"

api "github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis/config"
)

//go:embed kubecost.yaml
Expand Down Expand Up @@ -55,15 +57,15 @@ data:
`, token)
}

func Render(config KubeCostConfig, compress bool) ([]byte, error) {
func Render(config *api.Configuration, compress bool) ([]byte, error) {
opts := yttcmd.NewOptions()
noopUI := yttui.NewCustomWriterTTY(false, os.Stderr, os.Stderr)

var files []*yttfiles.File
files = append(files, templateAsFile("manifest.yaml", manifest))
files = append(files, templateAsFile("grafana.yaml", grafanaOverlay))
files = append(files, templateAsFile("pvc.yaml", pvcOverlay))
files = append(files, templateAsFile("api-key.yaml", kubeCostTokenOverlay(config.ApiKey)))
files = append(files, templateAsFile("api-key.yaml", kubeCostTokenOverlay(config.ApiToken)))
files = append(files, templateAsFile("labels.yaml", labelsOverlay))
inputs := yttcmd.Input{Files: yttfiles.NewSortedFiles(files)}

Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/config/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

// +k8s:deepcopy-gen=package
// +groupName=kubecost.extensions.config.gardener.cloud

package config
41 changes: 41 additions & 0 deletions pkg/apis/config/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package config

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName is the group name use in this package
const GroupName = "kubecost.extensions.config.gardener.cloud"

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

// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder used to register the Shoot resource.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a pointer to SchemeBuilder.AddToScheme.
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Configuration{},
)
return nil
}
14 changes: 14 additions & 0 deletions pkg/apis/config/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package config

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

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

// Configuration contains information about the rsyslog relp extension configuration.
type Configuration struct {
metav1.TypeMeta

ApiToken string
}
13 changes: 13 additions & 0 deletions pkg/apis/config/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
14 changes: 14 additions & 0 deletions pkg/apis/config/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

// +k8s:deepcopy-gen=package
// +k8s:conversion-gen=github.com/liquid-reply/gardener-extension-shoot-kubecost/pkg/apis/config
// +k8s:defaulter-gen=TypeMeta
// +k8s:openapi-gen=true

//go:generate gen-crd-api-reference-docs -api-dir . -config ../../../../hack/api-reference/config.json -template-dir "$GARDENER_HACK_DIR/api-reference/template" -out-file ../../../../hack/api-reference/config.md

// Package v1alpha1 contains the rsyslog relps extension configuration.
// +groupName=kubecost.extensions.config.gardener.cloud
package v1alpha1
48 changes: 48 additions & 0 deletions pkg/apis/config/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// GroupName is the group name use in this package
const GroupName = "kubecost.extensions.config.gardener.cloud"

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

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

var (
// SchemeBuilder used to register the Configuration resource.
localSchemeBuilder = runtime.NewSchemeBuilder(addDefaultingFuncs, addKnownTypes)
// AddToScheme is a pointer to SchemeBuilder.AddToScheme.
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
// localSchemeBuilder.Register(addDefaultingFuncs)
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Configuration{},
)
return nil
}
19 changes: 19 additions & 0 deletions pkg/apis/config/v1alpha1/types_kubecost.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

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

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

// Configuration contains information about the rsyslog relp extension configuration.
type Configuration struct {
metav1.TypeMeta `json:",inline"`

ApiToken string `json:"apiToken"`
}
54 changes: 54 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.conversion.go

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

37 changes: 37 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.deepcopy.go

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

19 changes: 19 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.defaults.go

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

Loading

0 comments on commit 5ae6089

Please sign in to comment.