Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Runtime SDK client and Discovery #6455

Merged
merged 1 commit into from
May 11, 2022
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
8 changes: 5 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ linters-settings:
# CAPI exp runtime
- pkg: sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1
alias: runtimev1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1
alias: runtimehooksv1
# CAPD
- pkg: sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1alpha3
alias: infrav1alpha3
Expand Down Expand Up @@ -217,19 +219,19 @@ issues:
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: .*(api|types)\/.*\/conversion.*\.go$
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
text: "var-naming: don't use underscores in Go names;"
path: .*(api|types)\/.*\/conversion.*\.go$
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
text: "receiver-naming: receiver name"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1003: should not use underscores in Go names;"
path: .*(api|types)\/.*\/conversion.*\.go$
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1016: methods on the same type should have the same receiver name"
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for co
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/addons/api/... \
paths=./$(EXP_DIR)/runtime/api/... \
paths=./$(EXP_DIR)/runtime/hooks/api/... \
paths=./cmd/clusterctl/... \
paths=./internal/test/builder/...

Expand All @@ -270,6 +271,7 @@ generate-go-conversions: ## Run all generate-go-conversions-* targets
generate-go-conversions-core: $(CONVERSION_GEN) ## Generate conversions go code for core
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
$(MAKE) clean-generated-conversions SRC_DIRS="./api/v1alpha3,./$(EXP_DIR)/api/v1alpha3,./$(EXP_DIR)/addons/api/v1alpha3"
$(MAKE) clean-generated-conversions SRC_DIRS="./api/v1alpha4,./$(EXP_DIR)/api/v1alpha4,./$(EXP_DIR)/addons/api/v1alpha4"
$(MAKE) clean-generated-conversions SRC_DIRS="./internal/runtime/catalog/test/v1alpha1,./internal/runtime/catalog/test/v1alpha2"
$(CONVERSION_GEN) \
--input-dirs=./api/v1alpha3 \
--input-dirs=./api/v1alpha4 \
Expand All @@ -285,6 +287,12 @@ generate-go-conversions-core: $(CONVERSION_GEN) ## Generate conversions go code
--extra-peer-dirs=sigs.k8s.io/cluster-api/api/v1alpha4 \
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt
$(CONVERSION_GEN) \
--input-dirs=./internal/runtime/catalog/test/v1alpha1 \
--input-dirs=./internal/runtime/catalog/test/v1alpha2 \
--build-tag=ignore_autogenerated_runtime \
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-go-conversions-kubeadm-bootstrap
generate-go-conversions-kubeadm-bootstrap: $(CONVERSION_GEN) ## Generate conversions go code for kubeadm bootstrap
Expand Down
29 changes: 29 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2022 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.
*/

package v1alpha1

// ResponseStatus represents the status of the hook response.
// +enum
type ResponseStatus string

const (
// ResponseStatusSuccess represents the success response.
ResponseStatusSuccess ResponseStatus = "Success"

// ResponseStatusFailure represents a failure response.
ResponseStatusFailure ResponseStatus = "Failure"
)
92 changes: 92 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/discovery_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2022 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.
*/

package v1alpha1

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

"sigs.k8s.io/cluster-api/internal/runtime/catalog"
)

// DiscoveryRequest represents the object of a discovery request.
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
// +kubebuilder:object:root=true
type DiscoveryRequest struct {
metav1.TypeMeta `json:",inline"`
}

// DiscoveryResponse represents the object received as a discovery response.
fabriziopandini marked this conversation as resolved.
Show resolved Hide resolved
// +kubebuilder:object:root=true
type DiscoveryResponse struct {
metav1.TypeMeta `json:",inline"`

// Status of the call. One of "Success" or "Failure".
Status ResponseStatus `json:"status"`

// A human-readable description of the status of the call.
Message string `json:"message"`

// Handlers defines the current ExtensionHandlers supported by an Extension.
Handlers []ExtensionHandler `json:"handlers"`
}

// ExtensionHandler represents the discovery information of the extension which includes
// the hook it supports.
type ExtensionHandler struct {
// Name is the name of the ExtensionHandler.
Name string `json:"name"`

// RequestHook defines the versioned runtime hook which this ExtensionHandler serves.
RequestHook GroupVersionHook `json:"requestHook"`

// TimeoutSeconds defines the timeout duration for client calls to the ExtensionHandler.
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`

// FailurePolicy defines how failures in calls to the ExtensionHandler should be handled by a client.
FailurePolicy *FailurePolicy `json:"failurePolicy,omitempty"`
}

// GroupVersionHook defines the runtime hook when the ExtensionHandler is called.
type GroupVersionHook struct {
// APIVersion is the Version of the Hook
APIVersion string `json:"apiVersion"`

// Hook is the name of the hook
Hook string `json:"hook"`
}

// FailurePolicy is the type of a extension failure policy.
type FailurePolicy string

const (
// FailurePolicyIgnore means that an error calling the extension is ignored.
FailurePolicyIgnore FailurePolicy = "Ignore"

// FailurePolicyFail means that an error calling the extension is not ignored.
FailurePolicyFail FailurePolicy = "Fail"
)

// Discovery represents the discovery hook.
func Discovery(*DiscoveryRequest, *DiscoveryResponse) {}

func init() {
catalogBuilder.RegisterHook(Discovery, &catalog.HookMeta{
Tags: []string{"Discovery"},
Summary: "Discovery endpoint",
Description: "Discovery endpoint discovers the supported hooks of a RuntimeExtension",
Singleton: true,
})
}
20 changes: 20 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2022 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.
*/

// Package v1alpha1 contains the v1alpha1 RuntimeHooks.
// +kubebuilder:object:generate=true
// +k8s:openapi-gen=true
package v1alpha1
37 changes: 37 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2022 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.
*/

package v1alpha1

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

"sigs.k8s.io/cluster-api/internal/runtime/catalog"
)

var (
// GroupVersion is group version identifying RuntimeHooks defined in this package
// and their request and response types.
GroupVersion = schema.GroupVersion{Group: "hooks.runtime.cluster.x-k8s.io", Version: "v1alpha1"}

// catalogBuilder is used to add RuntimeHooks and their request and response types
// to a Catalog.
catalogBuilder = &catalog.Builder{GroupVersion: GroupVersion}

// AddToCatalog adds RuntimeHooks defined in this package and their request and
// response types to a catalog.
AddToCatalog = catalogBuilder.AddToCatalog
)
122 changes: 122 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/zz_generated.deepcopy.go

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

Loading