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]>
  • Loading branch information
Yuvaraj Kakaraparthi and chrischdi committed Apr 28, 2022
1 parent a1122e2 commit cf8378d
Show file tree
Hide file tree
Showing 9 changed files with 729 additions and 0 deletions.
1 change: 1 addition & 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
27 changes: 27 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
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 ResponseStatus = "Success"

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

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"
)

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"`
}

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"`
}

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
43 changes: 43 additions & 0 deletions exp/runtime/hooks/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
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

// localSchemeBuilder provide access to the SchemeBuilder used for managing rpc
// method's request and response types defined in this package.
// NOTE: this object is required to allow registration of automatically generated
// conversions func.
localSchemeBuilder = catalogBuilder
)
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))
}
Loading

0 comments on commit cf8378d

Please sign in to comment.