Skip to content

Commit

Permalink
Drop internal version of nodeagent.config.gardener.cloud API (garde…
Browse files Browse the repository at this point in the history
…ner#11097)

* Move API validation

* Drop internal API version

* Adapt entrypoint

* Adapt imports

* Update skaffold dependencies
  • Loading branch information
timebertt authored and RadaBDimitrova committed Jan 15, 2025
1 parent b4ea721 commit 1409d66
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 814 deletions.
15 changes: 7 additions & 8 deletions cmd/gardener-node-agent/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/gardener/gardener/pkg/features"
gardenerhealthz "github.com/gardener/gardener/pkg/healthz"
"github.com/gardener/gardener/pkg/nodeagent"
"github.com/gardener/gardener/pkg/nodeagent/apis/config"
nodeagentconfigv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
"github.com/gardener/gardener/pkg/nodeagent/bootstrap"
"github.com/gardener/gardener/pkg/nodeagent/controller"
Expand Down Expand Up @@ -102,7 +101,7 @@ func getBootstrapCommand(opts *options) *cobra.Command {
return bootstrapCmd
}

func run(ctx context.Context, cancel context.CancelFunc, log logr.Logger, cfg *config.NodeAgentConfiguration) error {
func run(ctx context.Context, cancel context.CancelFunc, log logr.Logger, cfg *nodeagentconfigv1alpha1.NodeAgentConfiguration) error {
log.Info("Feature Gates", "featureGates", features.DefaultFeatureGate)
fs := afero.Afero{Fs: afero.NewOsFs()}

Expand All @@ -117,9 +116,9 @@ func run(ctx context.Context, cancel context.CancelFunc, log logr.Logger, cfg *c
}

var extraHandlers map[string]http.Handler
if cfg.Debugging != nil && cfg.Debugging.EnableProfiling {
if cfg.Debugging != nil && ptr.Deref(cfg.Debugging.EnableProfiling, false) {
extraHandlers = routes.ProfilingHandlers
if cfg.Debugging.EnableContentionProfiling {
if ptr.Deref(cfg.Debugging.EnableContentionProfiling, false) {
goruntime.SetBlockProfileRate(1)
}
}
Expand Down Expand Up @@ -215,10 +214,10 @@ func run(ctx context.Context, cancel context.CancelFunc, log logr.Logger, cfg *c
return mgr.Start(ctx)
}

func getRESTConfig(ctx context.Context, log logr.Logger, fs afero.Afero, cfg *config.NodeAgentConfiguration) (*rest.Config, error) {
func getRESTConfig(ctx context.Context, log logr.Logger, fs afero.Afero, cfg *nodeagentconfigv1alpha1.NodeAgentConfiguration) (*rest.Config, error) {
if len(cfg.ClientConnection.Kubeconfig) > 0 {
log.Info("Creating REST config from client configuration")
restConfig, err := kubernetes.RESTConfigFromInternalClientConnectionConfiguration(&cfg.ClientConnection, nil, kubernetes.AuthTokenFile)
restConfig, err := kubernetes.RESTConfigFromClientConnectionConfiguration(&cfg.ClientConnection, nil, kubernetes.AuthTokenFile)
if err != nil {
return nil, fmt.Errorf("failed getting REST config from client connection configuration: %w", err)
}
Expand Down Expand Up @@ -298,7 +297,7 @@ func getRESTConfig(ctx context.Context, log logr.Logger, fs afero.Afero, cfg *co
return getRESTConfigNodeAgentAuthorizer(ctx, log, fs, cfg)
}

func getRESTConfigNodeAgentAuthorizer(ctx context.Context, log logr.Logger, fs afero.Afero, cfg *config.NodeAgentConfiguration) (*rest.Config, error) {
func getRESTConfigNodeAgentAuthorizer(ctx context.Context, log logr.Logger, fs afero.Afero, cfg *nodeagentconfigv1alpha1.NodeAgentConfiguration) (*rest.Config, error) {
if kubeconfigExists, err := fs.Exists(nodeagentconfigv1alpha1.KubeconfigFilePath); err != nil {
return nil, fmt.Errorf("failed checking whether kubeconfig file %q exists: %w", nodeagentconfigv1alpha1.KubeconfigFilePath, err)
} else if !kubeconfigExists {
Expand Down Expand Up @@ -346,7 +345,7 @@ func getRESTConfigNodeAgentAuthorizer(ctx context.Context, log logr.Logger, fs a
}

// TODO(oliver-goetz): Remove this function when NodeAgentAuthorizer feature gate is removed.
func getRESTConfigAccessToken(log logr.Logger, cfg *config.NodeAgentConfiguration) (*rest.Config, error) {
func getRESTConfigAccessToken(log logr.Logger, cfg *nodeagentconfigv1alpha1.NodeAgentConfiguration) (*rest.Config, error) {
restConfig := &rest.Config{
Burst: int(cfg.ClientConnection.Burst),
QPS: cfg.ClientConnection.QPS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
clientcmdv1 "k8s.io/client-go/tools/clientcmd/api/v1"

"github.com/gardener/gardener/pkg/component/extensions/operatingsystemconfig/original/components/kubelet"
"github.com/gardener/gardener/pkg/nodeagent/apis/config"
nodeagentconfigv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
kubernetesutils "github.com/gardener/gardener/pkg/utils/kubernetes"
)
Expand All @@ -28,7 +27,7 @@ import (
type KubeletBootstrapKubeconfig struct {
Log logr.Logger
FS afero.Afero
APIServerConfig config.APIServer
APIServerConfig nodeagentconfigv1alpha1.APIServer
}

// Start performs creation of the bootstrap kubeconfig.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"

. "github.com/gardener/gardener/cmd/gardener-node-agent/app/bootstrappers"
"github.com/gardener/gardener/pkg/nodeagent/apis/config"
nodeagentconfigv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
"github.com/gardener/gardener/pkg/utils"
"github.com/gardener/gardener/pkg/utils/test"
)
Expand All @@ -26,7 +26,7 @@ var _ = Describe("KubeletBootstrapKubeconfig", func() {
log = logr.Discard()

fakeFS afero.Afero
apiServerConfig = config.APIServer{
apiServerConfig = nodeagentconfigv1alpha1.APIServer{
Server: "server",
CABundle: []byte("ca-bundle"),
}
Expand Down
13 changes: 4 additions & 9 deletions cmd/gardener-node-agent/app/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,21 @@ import (

"github.com/gardener/gardener/cmd/utils/initrun"
"github.com/gardener/gardener/pkg/features"
"github.com/gardener/gardener/pkg/nodeagent/apis/config"
nodeagentconfigv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
nodeagentvalidation "github.com/gardener/gardener/pkg/nodeagent/apis/config/validation"
nodeagentvalidation "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1/validation"
)

var configDecoder runtime.Decoder

func init() {
configScheme := runtime.NewScheme()
schemeBuilder := runtime.NewSchemeBuilder(
config.AddToScheme,
nodeagentconfigv1alpha1.AddToScheme,
)
utilruntime.Must(schemeBuilder.AddToScheme(configScheme))
utilruntime.Must(nodeagentconfigv1alpha1.AddToScheme(configScheme))
configDecoder = serializer.NewCodecFactory(configScheme).UniversalDecoder()
}

type options struct {
configFile string
config *config.NodeAgentConfiguration
config *nodeagentconfigv1alpha1.NodeAgentConfiguration
}

var _ initrun.Options = &options{}
Expand All @@ -53,7 +48,7 @@ func (o *options) Complete() error {
return fmt.Errorf("error reading config file: %w", err)
}

o.config = &config.NodeAgentConfiguration{}
o.config = &nodeagentconfigv1alpha1.NodeAgentConfiguration{}
if err = runtime.DecodeInto(configDecoder, data, o.config); err != nil {
return fmt.Errorf("error decoding config: %w", err)
}
Expand Down
2 changes: 0 additions & 2 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,10 @@ nodeagent_groups() {

kube::codegen::gen_helpers \
--boilerplate "${PROJECT_ROOT}/hack/LICENSE_BOILERPLATE.txt" \
--extra-peer-dir github.com/gardener/gardener/pkg/nodeagent/apis/config \
--extra-peer-dir github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1 \
--extra-peer-dir k8s.io/apimachinery/pkg/apis/meta/v1 \
--extra-peer-dir k8s.io/apimachinery/pkg/conversion \
--extra-peer-dir k8s.io/apimachinery/pkg/runtime \
--extra-peer-dir k8s.io/component-base/config \
--extra-peer-dir k8s.io/component-base/config/v1alpha1 \
"${PROJECT_ROOT}/pkg/nodeagent/apis/config"
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/nodeagent/apis/config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
//
// SPDX-License-Identifier: Apache-2.0

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

package config
42 changes: 0 additions & 42 deletions pkg/nodeagent/apis/config/register.go

This file was deleted.

107 changes: 0 additions & 107 deletions pkg/nodeagent/apis/config/types.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/nodeagent/apis/config/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: Apache-2.0

// +k8s:deepcopy-gen=package
// +k8s:conversion-gen=github.com/gardener/gardener/pkg/nodeagent/apis/config
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/gardener/gardener/pkg/logger"
"github.com/gardener/gardener/pkg/nodeagent/apis/config"
nodeagentconfigv1alpha1 "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
"github.com/gardener/gardener/pkg/utils/validation/kubernetesversion"
)

// ValidateNodeAgentConfiguration validates the given `NodeAgentConfiguration`.
func ValidateNodeAgentConfiguration(conf *config.NodeAgentConfiguration) field.ErrorList {
func ValidateNodeAgentConfiguration(conf *nodeagentconfigv1alpha1.NodeAgentConfiguration) field.ErrorList {
allErrs := field.ErrorList{}

if conf.LogLevel != "" && !sets.New(logger.AllLogLevels...).Has(conf.LogLevel) {
Expand All @@ -34,13 +34,13 @@ func ValidateNodeAgentConfiguration(conf *config.NodeAgentConfiguration) field.E
return allErrs
}

func validateBootstrapConfiguration(_ *config.BootstrapConfiguration, _ *field.Path) field.ErrorList {
func validateBootstrapConfiguration(_ *nodeagentconfigv1alpha1.BootstrapConfiguration, _ *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

return allErrs
}

func validateControllerConfiguration(conf config.ControllerConfiguration, fldPath *field.Path) field.ErrorList {
func validateControllerConfiguration(conf nodeagentconfigv1alpha1.ControllerConfiguration, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

allErrs = append(allErrs, validateOperatingSystemConfigControllerConfiguration(conf.OperatingSystemConfig, fldPath.Child("operatingSystemConfig"))...)
Expand All @@ -49,7 +49,7 @@ func validateControllerConfiguration(conf config.ControllerConfiguration, fldPat
return allErrs
}

func validateOperatingSystemConfigControllerConfiguration(conf config.OperatingSystemConfigControllerConfig, fldPath *field.Path) field.ErrorList {
func validateOperatingSystemConfigControllerConfiguration(conf nodeagentconfigv1alpha1.OperatingSystemConfigControllerConfig, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

if conf.SecretName == "" {
Expand All @@ -67,7 +67,7 @@ func validateOperatingSystemConfigControllerConfiguration(conf config.OperatingS
return allErrs
}

func validateTokenControllerConfiguration(conf config.TokenControllerConfig, fldPath *field.Path) field.ErrorList {
func validateTokenControllerConfiguration(conf nodeagentconfigv1alpha1.TokenControllerConfig, fldPath *field.Path) field.ErrorList {
var (
allErrs = field.ErrorList{}
paths = sets.New[string]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import (

func TestValidation(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "NodeAgent APIs Config Validation Suite")
RunSpecs(t, "NodeAgent APIs Config V1alpha1 Validation Suite")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"

. "github.com/gardener/gardener/pkg/nodeagent/apis/config"
. "github.com/gardener/gardener/pkg/nodeagent/apis/config/validation"
. "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1"
. "github.com/gardener/gardener/pkg/nodeagent/apis/config/v1alpha1/validation"
)

var _ = Describe("#ValidateNodeAgentConfiguration", func() {
Expand Down
Loading

0 comments on commit 1409d66

Please sign in to comment.