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

RFC: dynamic resource allocation prototype #1

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e389b27
Validate dry-run and force flags can not be used same time in replace
ardaguclu Jun 1, 2022
b722056
add unit test
zhoumingcheng Jun 21, 2022
466c4d2
pkg/kubelet: skip long test on short mode
rata Jun 24, 2022
a4f966a
Graduate SeccompDefault feature to beta
saschagrunert Jun 27, 2022
7a95525
Create ControllerRevision lifecycle e2e test
heyste May 9, 2022
93701ce
cleanup: Removes duplicate utils code
claudiubelu Jun 29, 2022
14708f2
agnhost: Check symlink target's permissions for Windows
claudiubelu Aug 27, 2021
61ebfdb
Add cases for when --timeout=0 and tests
mpuckett159 Jul 1, 2022
d3092cd
scheduler: do not update sched.nextStartNodeIndex when evaluate nomin…
SataQiu Jul 4, 2022
88c6deb
Update `godoc.org` to `pkg.go.dev ` in kubeadm
Jul 7, 2022
8aeee52
kubeadm: De-dup the confirmation on the interactive cmds
chendave Jul 6, 2022
3581e30
build: update to klog v2.70.1
pohly Jul 7, 2022
e41f2a1
Change error messages
ardaguclu Jul 7, 2022
8d2c737
Merge pull request #110997 from mengjiao-liu/update-godoc-link
k8s-ci-robot Jul 7, 2022
9d68640
Merge pull request #110923 from mpuckett159/fix/add-wait-timers
k8s-ci-robot Jul 7, 2022
6adee9d
Merge pull request #110947 from SataQiu/scheduler-20220704
k8s-ci-robot Jul 7, 2022
d2a94fe
Remove SIG Scheduling approvers from reviewers
alculquicondor Jul 7, 2022
e9b96b1
Merge pull request #111004 from alculquicondor/patch-4
k8s-ci-robot Jul 7, 2022
34b9f0d
Merge pull request #110998 from chendave/de_dup_kubeadm
k8s-ci-robot Jul 7, 2022
f218f7b
Computation of the StorageVersionHash use overridden storage versions…
249043822 Jul 1, 2022
6d5cccf
Merge pull request #110122 from ii/create-controller-revision-test
k8s-ci-robot Jul 8, 2022
2b657a0
Merge pull request #110805 from saschagrunert/seccomp-default-beta
k8s-ci-robot Jul 8, 2022
8e62fd2
Merge pull request #111001 from pohly/klog-update
k8s-ci-robot Jul 8, 2022
6732550
Merge pull request #110877 from claudiubelu/agnhost-windows-file-perm…
k8s-ci-robot Jul 8, 2022
9509211
Merge pull request #110904 from 249043822/storageversion
k8s-ci-robot Jul 8, 2022
857458c
update ginkgo from v1 to v2 and gomega to 1.19.0
chendave Mar 29, 2022
05c0f4a
Define the const of `GINKGO_PANIC` directly
chendave Mar 29, 2022
2eb8e9e
`ginkgo.It` doesn't have a `timeout` arg anymore
chendave Mar 29, 2022
ece0bb3
Adapt to new type of `GinkgoWriter`
chendave Mar 29, 2022
375b2a5
Build `Ginkgo` binary
chendave Mar 29, 2022
f792256
e2e: adapt output tests to Ginkgo v2 and Gomega 1.19
chendave Mar 30, 2022
b57bade
Switch to use `dry-run` option to generate test spec
chendave Apr 15, 2022
dd58016
Implement `DetailsReporter` report within `ReportAfterSuite`
chendave Apr 15, 2022
20498fd
Generate conformance test spec with `offset` decorator
chendave Apr 15, 2022
2084f3c
Drop all stacktrace related validtion
chendave Apr 15, 2022
2f3028c
Define the `timeout` to `24h` for Ginkgo V2
chendave Apr 20, 2022
fd4b5b6
Stop using the deprecated method `CurrentGinkgoTestDescription`
chendave Apr 24, 2022
46a3954
Migrate `ProgressReporter` to `Ginkgo` V2
chendave May 2, 2022
5ac8105
Set Ginkgo config by the method of `GinkgoConfiguration()`
chendave May 2, 2022
82ac6be
Custom reporter of Junit report is no longer needed
chendave May 2, 2022
3833695
Redirect `klog` out to `GinkgoWriter`
chendave Apr 29, 2022
05c513d
`ginkgo.By` can only be used inside a runnable node
chendave May 12, 2022
f7427d0
build: add ginkgo aliases for WHAT
pohly Jun 8, 2022
50d1b6c
Add Ginkgo v1 to the list of unwanted dependencies
chendave Jul 4, 2022
ebcc583
Merge pull request #110326 from ardaguclu/add-validation-replace
k8s-ci-robot Jul 8, 2022
c05d185
Merge pull request #110683 from zhoumingcheng/master-v2
k8s-ci-robot Jul 8, 2022
0dc32b1
Merge pull request #110774 from kinvolk/rata/kubelet-short-tests
k8s-ci-robot Jul 8, 2022
80b2848
Merge pull request #110860 from claudiubelu/utils-cleanup
k8s-ci-robot Jul 8, 2022
4569e64
Merge pull request #109111 from chendave/ginkgo_upstream
k8s-ci-robot Jul 8, 2022
eccf7c6
kube features: add DynamicResourceAllocation
pohly Mar 22, 2022
4a5f531
initial dynamic resource allocation API types
pohly Feb 26, 2022
997a22d
api: generated files for dynamic resource allocation
pohly Jul 4, 2022
7cd8d96
dynamic resource allocation: implement printers
pohly Mar 1, 2022
a331efc
cdi: example driver
pohly Mar 18, 2022
bc8c200
component-helpers: add ResourceClaim support code
pohly Mar 22, 2022
de44076
ResourceClaim controller: clone from pkg/controller/volume/ephemeral
pohly Mar 22, 2022
32f6d7a
kube-controller-manager: add ResourceClaim controller
pohly Mar 22, 2022
3d85228
scheduler: add dynamic resource allocation plugin
pohly Apr 12, 2022
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
Prev Previous commit
Next Next commit
cdi: example driver
The logic of the driver is very simple (no real allocation, just set some env
variables). The main purpose is to develop and test the code that integrates
with Kubernetes.
  • Loading branch information
pohly committed Aug 1, 2022
commit a331efcd0cd42ad168e58e24621dc66739a4dcf3
11 changes: 11 additions & 0 deletions test/integration/cdi/example-driver/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See the OWNERS docs at https://go.k8s.io/owners

approvers:
- klueska
- pohly
reviewers:
- klueska
- pohly
- bart0sh
labels:
- sig/node
68 changes: 68 additions & 0 deletions test/integration/cdi/example-driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# cdi-example-driver

The cdi-example-driver implements a resource driver controller and a resource
kubelet plugin in a single binary. This is done in a single binary to minimize
the amount of boilerplate code. "Real" drivers could also implement both in
different binaries.

## Usage

The cdi-example-driver can get deployed as a Deployment for the controller,
with leader election. A DaemonSet is used for the kubelet plugin. It can also
run as a Kubernetes client outside of a cluster.

The actual functionality is initially very limited. Resources are unlimited, so
all ResourceClaims can be allocated. Valid ResourceClaims parameters are
key/value string pairs:

```yaml
kind: ResourceClaim
spec:
parameters:
some: example
another: example2
```

Those get copied into the ResourceClaimStatus with "user_" and "admin_" as
prefix, depending on whether they came from the ResourceClaim or ResourceClass:

```yaml
kind: ResourceClaim
status:
phase: Allocated
allocation:
userLimit: -1
attributes:
user_some: example
user_another: example
```

The kubelet plugin then sets these attributes as environment variables in each
container that uses the resource.

While the functionality itself is very limited, the code strives to showcase
best practices and supports metrics, leader election, and the same logging
options as Kubernetes.

## Design

The binary itself is a Cobra command with two operations, `controller` and
`kubelet-plugin`. Logging is done with [contextual
logging](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging).

The `controller` package implements the interaction with
ResourceClaims. It is generic and relies on an interface to implement the
actual driver logic. Long-term that part could be split out into a reusable
utility package.

`app` is the driver itself with a very simple implementation of the interface
expected by `controller`.

## Prior art

Some of this code was derived from the
[external-resizer](https://github.com/kubernetes-csi/external-resizer/). `controller`
corresponds to the [controller
logic](https://github.com/kubernetes-csi/external-resizer/blob/master/pkg/controller/controller.go),
which in turn is similar to the
[sig-storage-lib-external-provisioner](https://github.com/kubernetes-sigs/sig-storage-lib-external-provisioner).
111 changes: 111 additions & 0 deletions test/integration/cdi/example-driver/app/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
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 app does all of the work necessary to configure and run a
// Kubernetes app process.
package app

import (
"context"
"encoding/json"
"fmt"
"strings"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"

"k8s.io/kubernetes/test/integration/cdi/example-driver/controller"
)

func runController(ctx context.Context, clientset kubernetes.Interface, driverName string, workers int) {
driver := &exampleDriver{
clientset: clientset,
}
informerFactory := informers.NewSharedInformerFactory(clientset, 0 /* resync period */)
ctrl := controller.New(ctx, driverName, driver, clientset, informerFactory)
informerFactory.Start(ctx.Done())
ctrl.Run(workers)
}

type exampleDriver struct {
clientset kubernetes.Interface
}
type parameters map[string]string

var _ controller.Driver = exampleDriver{}

func (d exampleDriver) GetClassParameters(ctx context.Context, class *corev1.ResourceClass) (interface{}, error) {
// TODO: read config map, but from what namespace?!
var p parameters
return p, nil
}

func (d exampleDriver) GetClaimParameters(ctx context.Context, claim *corev1.ResourceClaim, class *corev1.ResourceClass, classParameters interface{}) (interface{}, error) {
if claim.Spec.Parameters != nil {
if claim.Spec.Parameters.APIVersion != "v1" ||
claim.Spec.Parameters.Kind != "ConfigMap" {
return nil, fmt.Errorf("claim parameters are only supported in APIVersion v1, Kind ConfigMap, got: %v", claim.Spec.Parameters)
}
return d.readParametersFromConfigMap(ctx, claim.Namespace, claim.Spec.Parameters.Name)
}
return nil, nil
}

func (d exampleDriver) readParametersFromConfigMap(ctx context.Context, namespace, name string) (parameters, error) {
configMap, err := d.clientset.CoreV1().ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("get config map: %v", err)
}
return parameters(configMap.Data), nil
}

// Allocate simply copies parameters as JSON map into ResourceHandle.
func (d exampleDriver) Allocate(ctx context.Context, claim *corev1.ResourceClaim, claimParameters interface{}, class *corev1.ResourceClass, classParameters interface{}, selectedNode string) (*corev1.AllocationResult, error) {
allocation := &corev1.AllocationResult{
SharedResource: true,
}
p := parameters{}
toEnvVars("user", claimParameters.(parameters), p)
toEnvVars("admin", classParameters.(parameters), p)
data, err := json.Marshal(p)
if err != nil {
return nil, fmt.Errorf("encode env variables: %v", err)
}
allocation.ResourceHandle = string(data)
return allocation, nil
}

func (d exampleDriver) StopAllocation(ctx context.Context, claim *corev1.ResourceClaim) error {
return nil
}

func (d exampleDriver) Deallocate(ctx context.Context, claim *corev1.ResourceClaim) error {
return nil
}

func (d exampleDriver) UnsuitableNodes(ctx context.Context, pod *v1.Pod, claims []*controller.ClaimAllocation, potentialNodes []string) error {
// All nodes are suitable.
return nil
}

func toEnvVars(what string, from, to parameters) {
for key, value := range from {
to[what+"_"+strings.ToLower(key)] = value
}
}
Loading