Skip to content

Commit

Permalink
Runtime SDK client and Discovery
Browse files Browse the repository at this point in the history
Co-authored-by: chrischdi <[email protected]>
Co-authored-by: sbueringer <[email protected]>
  • Loading branch information
3 people committed Apr 28, 2022
1 parent a1122e2 commit 48cda1a
Show file tree
Hide file tree
Showing 15 changed files with 986 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,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 Down Expand Up @@ -319,6 +320,16 @@ generate-go-conversions-kubeadm-control-plane: $(CONVERSION_GEN) ## Generate con
--output-file-base=zz_generated.conversion $(CONVERSION_GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate/boilerplate.generatego.txt

.PHONY: generate-go-conversions-runtime
generate-go-conversions-runtime: $(CONVERSION_GEN)
$(MAKE) clean-generated-conversions SRC_DIRS="./internal/runtime/catalog/test/v1alpha1,./internal/runtime/catalog/test/v1alpha2"
$(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-modules
generate-modules: ## Run go mod tidy to ensure modules are up to date
go mod tidy
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"
)
91 changes: 91 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/discovery_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
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"
)

// 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 causes the admission to fail.
FailurePolicyFail FailurePolicy = "Fail"
)

// Hook is a identifier of a runtime hook.
type Hook struct {
// APIVersion is the Version of the Hook
APIVersion string `json:"apiVersion"`

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

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

// Hook defines the specific runtime event for which this RuntimeExtension calls.
Hook Hook `json:"hook"`

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

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

// DiscoveryHookRequest foo bar baz.
// +kubebuilder:object:root=true
type DiscoveryHookRequest struct {
metav1.TypeMeta `json:",inline"`
}

// DiscoveryHookResponse foo bar baz.
// +kubebuilder:object:root=true
type DiscoveryHookResponse 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"`

Extensions []RuntimeExtension `json:"extensions"`
}

// Discovery represents the discovery hook.
func Discovery(*DiscoveryHookRequest, *DiscoveryHookResponse) {}

func init() {
catalogBuilder.RegisterHook(Discovery, &catalog.HookMeta{
Tags: []string{"Discovery"},
Summary: "Discovery endpoint",
Description: "Discovery endpoint discovers the supported hook of a runtime extension",
Singleton: true,
})
}
21 changes: 21 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
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 idl implementation for extension1.
// +k8s:conversion-gen=sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha3
// +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 rpc services 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 rpc services and their request and response types
// to a Catalog.
catalogBuilder = &catalog.Builder{GroupVersion: GroupVersion}

// AddToCatalog adds rpc services 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.

11 changes: 11 additions & 0 deletions internal/runtime/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,14 @@ func (gvh GroupVersionHook) String() string {
var emptyGroupVersionHook = GroupVersionHook{}

var emptyGroupVersionKind = schema.GroupVersionKind{}

// GVHToPath calculates the path for a given GroupVersionHook.
// This func is aligned with Kubernetes paths for cluster-wide resources, e.g.:
// /apis/storage.k8s.io/v1/storageclasses/standard.
// Note: name is only appended if set, e.g. the Discovery Hook does not have a name.
func GVHToPath(gvh GroupVersionHook, name string) string {
if name == "" {
return fmt.Sprintf("/%s/%s/%s", gvh.Group, gvh.Version, strings.ToLower(gvh.Hook))
}
return fmt.Sprintf("/%s/%s/%s/%s", gvh.Group, gvh.Version, strings.ToLower(gvh.Hook), strings.ToLower(name))
}
37 changes: 37 additions & 0 deletions internal/runtime/catalog/test/v1alpha1/conversion.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 (
conversion "k8s.io/apimachinery/pkg/conversion"

clusterv1alpha4 "sigs.k8s.io/cluster-api/api/v1alpha4"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
v1alpha2 "sigs.k8s.io/cluster-api/internal/runtime/catalog/test/v1alpha2"
)

func Convert_v1alpha1_FakeResponse_To_v1alpha2_FakeResponse(in *FakeResponse, out *v1alpha2.FakeResponse, s conversion.Scope) error {
return autoConvert_v1alpha1_FakeResponse_To_v1alpha2_FakeResponse(in, out, s)
}

func Convert_v1alpha4_Cluster_To_v1beta1_Cluster(in *clusterv1alpha4.Cluster, out *clusterv1.Cluster, s conversion.Scope) error {
return clusterv1alpha4.Convert_v1alpha4_Cluster_To_v1beta1_Cluster(in, out, s)
}

func Convert_v1beta1_Cluster_To_v1alpha4_Cluster(in *clusterv1.Cluster, out *clusterv1alpha4.Cluster, s conversion.Scope) error {
return clusterv1alpha4.Convert_v1beta1_Cluster_To_v1alpha4_Cluster(in, out, s)
}
Loading

0 comments on commit 48cda1a

Please sign in to comment.