diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 160220b9..6f21cebd 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -25,7 +25,7 @@ on: env: GO_VERSION: "1.24" - K8S_VERSION: "v1.33.1" + K8S_VERSION: "v1.34.0-beta.0.542+f9ed14bf9b1119" KIND_VERSION: "v0.28.0" IMAGE_NAME: ghcr.io/google/dranet KIND_CLUSTER_NAME: kind @@ -84,12 +84,12 @@ jobs: run: | TMP_DIR=$(mktemp -d) # Test binaries - curl -L https://dl.k8s.io/${{ env.K8S_VERSION }}/kubernetes-test-linux-amd64.tar.gz -o ${TMP_DIR}/kubernetes-test-linux-amd64.tar.gz + curl -L https://dl.k8s.io/ci/fast/${{ env.K8S_VERSION }}/kubernetes-test-linux-amd64.tar.gz -o ${TMP_DIR}/kubernetes-test-linux-amd64.tar.gz tar xvzf ${TMP_DIR}/kubernetes-test-linux-amd64.tar.gz \ --directory ${TMP_DIR} \ --strip-components=3 kubernetes/test/bin/ginkgo kubernetes/test/bin/e2e.test # kubectl - curl -L https://dl.k8s.io/${{ env.K8S_VERSION }}/bin/linux/amd64/kubectl -o ${TMP_DIR}/kubectl + curl -L https://dl.k8s.io/ci/fast/${{ env.K8S_VERSION }}/bin/linux/amd64/kubectl -o ${TMP_DIR}/kubectl # kind curl -Lo ${TMP_DIR}/kind https://kind.sigs.k8s.io/dl/${{ env.KIND_VERSION }}/kind-linux-amd64 # Install @@ -105,8 +105,11 @@ jobs: run: | # output_dir mkdir -p _artifacts + # build kind + kind_node_source="https://dl.k8s.io/ci/fast/${{ env.K8S_VERSION }}/kubernetes-server-linux-amd64.tar.gz" + kind build node-image --image=dra/node:latest "${kind_node_source}" # create cluster - kind create cluster --name ${{ env.KIND_CLUSTER_NAME}} --image kindest/node:${{ env.K8S_VERSION }} --config kind.yaml + kind create cluster --name ${{ env.KIND_CLUSTER_NAME}} --image dra/node:latest --config kind.yaml # dump the kubeconfig for later /usr/local/bin/kind get kubeconfig --name ${{ env.KIND_CLUSTER_NAME}} > _artifacts/kubeconfig.conf diff --git a/cmd/dranet/app.go b/cmd/dranet/app.go index 58a64832..36e8ba17 100644 --- a/cmd/dranet/app.go +++ b/cmd/dranet/app.go @@ -33,7 +33,7 @@ import ( "github.com/google/dranet/pkg/driver" "github.com/prometheus/client_golang/prometheus/promhttp" - resourcev1beta1 "k8s.io/api/resource/v1beta1" + resourcev1 "k8s.io/api/resource/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -58,7 +58,7 @@ func init() { flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file") flag.StringVar(&bindAddress, "bind-address", ":9177", "The IP address and port for the metrics and healthz server to serve on") flag.StringVar(&hostnameOverride, "hostname-override", "", "If non-empty, will be used as the name of the Node that kube-network-policies is running on. If unset, the node name is assumed to be the same as the node's hostname.") - flag.StringVar(&celExpression, "filter", `attributes["dra.net/type"].StringValue != "veth"`, "CEL expression to filter network interface attributes (v1beta1.DeviceAttribute).") + flag.StringVar(&celExpression, "filter", `attributes["dra.net/type"].StringValue != "veth"`, "CEL expression to filter network interface attributes (v1.DeviceAttribute).") flag.Usage = func() { fmt.Fprint(os.Stderr, "Usage: dranet [options]\n\n") @@ -128,9 +128,9 @@ func main() { if celExpression != "" { env, err := cel.NewEnv( ext.NativeTypes( - reflect.ValueOf(resourcev1beta1.DeviceAttribute{}), + reflect.ValueOf(resourcev1.DeviceAttribute{}), ), - cel.Variable("attributes", cel.MapType(cel.StringType, cel.ObjectType("v1beta1.DeviceAttribute"))), + cel.Variable("attributes", cel.MapType(cel.StringType, cel.ObjectType("v1.DeviceAttribute"))), ) if err != nil { klog.Fatalf("error creating CEL environment: %v", err) diff --git a/examples/deviceclass.yaml b/examples/deviceclass.yaml index 78981d2c..8e44280e 100644 --- a/examples/deviceclass.yaml +++ b/examples/deviceclass.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: DeviceClass metadata: name: dra.net diff --git a/examples/repeatresourceclaimtemplate.yaml b/examples/repeatresourceclaimtemplate.yaml index a2209d10..f1c09ffe 100644 --- a/examples/repeatresourceclaimtemplate.yaml +++ b/examples/repeatresourceclaimtemplate.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. --- -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: DeviceClass metadata: name: multinic @@ -21,7 +21,7 @@ spec: - cel: expression: device.driver == "dra.net" --- -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaimTemplate metadata: name: reapply-interfaces-template @@ -30,10 +30,11 @@ spec: devices: requests: - name: reapply-interfaces-template - deviceClassName: multinic - selectors: - - cel: - expression: device.attributes["dra.net"].ifName == "dummy8" + exactly: + deviceClassName: multinic + selectors: + - cel: + expression: device.attributes["dra.net"].ifName == "dummy8" --- apiVersion: apps/v1 kind: Deployment diff --git a/examples/resourceclaim.yaml b/examples/resourceclaim.yaml index 6ac38acc..f0d03091 100644 --- a/examples/resourceclaim.yaml +++ b/examples/resourceclaim.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaim metadata: name: dummy-interface-static-ip @@ -20,10 +20,11 @@ spec: devices: requests: - name: req-dummy - deviceClassName: dra.net - selectors: - - cel: - expression: device.attributes["dra.net"].type == "dummy" + exactly: + deviceClassName: dra.net + selectors: + - cel: + expression: device.attributes["dra.net"].type == "dummy" config: - opaque: driver: dra.net diff --git a/examples/resourceclaim_advanced.yaml b/examples/resourceclaim_advanced.yaml index 0bd40d6f..b1cd1090 100644 --- a/examples/resourceclaim_advanced.yaml +++ b/examples/resourceclaim_advanced.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaim metadata: name: dummy-interface-advanced @@ -20,10 +20,11 @@ spec: devices: requests: - name: req-dummy-advanced - deviceClassName: dra.net - selectors: - - cel: - expression: device.attributes["dra.net"].ifName == "dummy0" + exactly: + deviceClassName: dra.net + selectors: + - cel: + expression: device.attributes["dra.net"].ifName == "dummy0" config: - opaque: driver: dra.net diff --git a/examples/resourceclaim_bigtcp.yaml b/examples/resourceclaim_bigtcp.yaml index 41081370..8a962116 100644 --- a/examples/resourceclaim_bigtcp.yaml +++ b/examples/resourceclaim_bigtcp.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaim metadata: name: dummy-interface-bigtcp @@ -20,10 +20,11 @@ spec: devices: requests: - name: req-dummy-bigtcp - deviceClassName: dra.net - selectors: - - cel: - expression: device.attributes["dra.net"].ifName == "dummy0" + exactly: + deviceClassName: dra.net + selectors: + - cel: + expression: device.attributes["dra.net"].ifName == "dummy0" config: - opaque: driver: dra.net diff --git a/examples/resourceclaim_disable_ebpf.yaml b/examples/resourceclaim_disable_ebpf.yaml index 8d7d26ec..077ad546 100644 --- a/examples/resourceclaim_disable_ebpf.yaml +++ b/examples/resourceclaim_disable_ebpf.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaim metadata: name: dummy-interface-disable-ebpf @@ -20,10 +20,11 @@ spec: devices: requests: - name: req-dummy - deviceClassName: dra.net - selectors: - - cel: - expression: device.attributes["dra.net"].ifName == "dummy0" + exactly: + deviceClassName: dra.net + selectors: + - cel: + expression: device.attributes["dra.net"].ifName == "dummy0" config: - opaque: driver: dra.net diff --git a/examples/resourceclaim_route.yaml b/examples/resourceclaim_route.yaml index b5cec2a3..5e210b74 100644 --- a/examples/resourceclaim_route.yaml +++ b/examples/resourceclaim_route.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaim metadata: name: dummy-interface-static-ip-route @@ -20,10 +20,11 @@ spec: devices: requests: - name: req-dummy - deviceClassName: dra.net - selectors: - - cel: - expression: device.attributes["dra.net"].type == "dummy" + exactly: + deviceClassName: dra.net + selectors: + - cel: + expression: device.attributes["dra.net"].type == "dummy" config: - opaque: driver: dra.net diff --git a/examples/resourceclaimtemplate.yaml b/examples/resourceclaimtemplate.yaml index 827afd28..2fa214f4 100644 --- a/examples/resourceclaimtemplate.yaml +++ b/examples/resourceclaimtemplate.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. --- -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: DeviceClass metadata: name: multinic @@ -21,7 +21,7 @@ spec: - cel: expression: device.driver == "dra.net" --- -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaimTemplate metadata: name: phy-interfaces-template @@ -30,10 +30,11 @@ spec: devices: requests: - name: phy-interfaces-template - deviceClassName: multinic - selectors: - - cel: - expression: device.attributes["dra.net"].ifName == "dummy0" + exactly: + deviceClassName: multinic + selectors: + - cel: + expression: device.attributes["dra.net"].ifName == "dummy0" --- apiVersion: apps/v1 kind: Deployment diff --git a/examples/resourceclaimtemplate_double.yaml b/examples/resourceclaimtemplate_double.yaml index 7876a2f3..92488745 100644 --- a/examples/resourceclaimtemplate_double.yaml +++ b/examples/resourceclaimtemplate_double.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. --- -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: DeviceClass metadata: name: multinic @@ -21,7 +21,7 @@ spec: - cel: expression: device.driver == "dra.net" --- -apiVersion: resource.k8s.io/v1beta1 +apiVersion: resource.k8s.io/v1 kind: ResourceClaimTemplate metadata: name: phy-interfaces-template @@ -30,11 +30,12 @@ spec: devices: requests: - name: phy-interfaces-template - count: 2 - deviceClassName: multinic - selectors: - - cel: - expression: device.attributes["dra.net"].ifName == "dummy0" || device.attributes["dra.net"].ifName == "dummy1" + exactly: + count: 2 + deviceClassName: multinic + selectors: + - cel: + expression: device.attributes["dra.net"].ifName == "dummy0" || device.attributes["dra.net"].ifName == "dummy1" --- apiVersion: apps/v1 kind: Deployment diff --git a/go.mod b/go.mod index e86d0a39..13c6d045 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,15 @@ module github.com/google/dranet go 1.24.0 +replace ( + k8s.io/api => github.com/kubernetes/kubernetes/staging/src/k8s.io/api v0.0.0-20250724145648-d21da29c9ec4 + k8s.io/apimachinery => github.com/kubernetes/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20250724145648-d21da29c9ec4 + k8s.io/client-go => github.com/kubernetes/kubernetes/staging/src/k8s.io/client-go v0.0.0-20250724145648-d21da29c9ec4 + k8s.io/component-base => github.com/kubernetes/kubernetes/staging/src/k8s.io/component-base v0.0.0-20250724145648-d21da29c9ec4 + k8s.io/dynamic-resource-allocation => github.com/kubernetes/kubernetes/staging/src/k8s.io/dynamic-resource-allocation v0.0.0-20250724145648-d21da29c9ec4 + k8s.io/kubelet => github.com/kubernetes/kubernetes/staging/src/k8s.io/kubelet v0.0.0-20250724145648-d21da29c9ec4 +) + require ( cloud.google.com/go/compute v1.41.0 cloud.google.com/go/compute/metadata v0.7.0 @@ -23,12 +32,12 @@ require ( golang.org/x/time v0.12.0 google.golang.org/api v0.243.0 google.golang.org/protobuf v1.36.6 - k8s.io/api v0.33.3 - k8s.io/apimachinery v0.33.3 - k8s.io/client-go v0.33.3 + k8s.io/api v0.34.0-beta.0 + k8s.io/apimachinery v0.34.0-beta.0 + k8s.io/client-go v0.34.0-beta.0 k8s.io/cloud-provider-gcp v0.0.0-20250326051131-7056e3facd39 - k8s.io/component-helpers v0.33.3 - k8s.io/dynamic-resource-allocation v0.33.3 + k8s.io/component-helpers v0.34.0-beta.0 + k8s.io/dynamic-resource-allocation v0.0.0 k8s.io/klog/v2 v2.130.1 k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 @@ -53,7 +62,7 @@ require ( github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/swag v0.23.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/google/gnostic-models v0.6.9 // indirect + github.com/google/gnostic-models v0.7.0 // indirect github.com/google/s2a-go v0.1.9 // indirect github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect @@ -67,12 +76,13 @@ require ( github.com/mdlayher/packet v1.1.2 // indirect github.com/mdlayher/socket v0.5.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/onsi/ginkgo/v2 v2.22.1 // indirect github.com/opencontainers/runtime-spec v1.2.1 // indirect github.com/pierrec/lz4/v4 v4.1.22 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.65.0 // indirect github.com/prometheus/procfs v0.16.1 // indirect @@ -90,6 +100,8 @@ require ( go.opentelemetry.io/otel/trace v1.36.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect + go.yaml.in/yaml/v2 v2.4.2 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/crypto v0.40.0 // indirect golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect golang.org/x/net v0.42.0 // indirect @@ -104,10 +116,10 @@ require ( gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/cri-api v0.33.3 // indirect - k8s.io/kube-openapi v0.0.0-20250610211856-8b98d1ed966a // indirect + k8s.io/cri-api v0.34.0-beta.0 // indirect + k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect k8s.io/kubelet v0.33.3 // indirect sigs.k8s.io/randfill v1.0.0 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect - sigs.k8s.io/yaml v1.4.0 // indirect + sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect + sigs.k8s.io/yaml v1.5.0 // indirect ) diff --git a/go.sum b/go.sum index ef4d3817..ee43b0a3 100644 --- a/go.sum +++ b/go.sum @@ -60,9 +60,8 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/cel-go v0.26.0 h1:DPGjXackMpJWH680oGY4lZhYjIameYmR+/6RBdDGmaI= github.com/google/cel-go v0.26.0/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM= -github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw= -github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= +github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -101,6 +100,16 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kubernetes/kubernetes/staging/src/k8s.io/api v0.0.0-20250724145648-d21da29c9ec4 h1:BGQvnslv9Gf3N0OmPbByiz/vnXLX8krdRGZG35gtbFc= +github.com/kubernetes/kubernetes/staging/src/k8s.io/api v0.0.0-20250724145648-d21da29c9ec4/go.mod h1:oAbiREintv4AjIOJp24Y0D6c/S0VsL2wSL8/KURHyLg= +github.com/kubernetes/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20250724145648-d21da29c9ec4 h1:SuZr2OP5j4ucAtwFuG3eopVq5zQa9rFc72F06Ys3LyM= +github.com/kubernetes/kubernetes/staging/src/k8s.io/apimachinery v0.0.0-20250724145648-d21da29c9ec4/go.mod h1:v1p1Jsze3IHLy5gU17yVqR2qLO7jgYeX6mw3HZy2AEU= +github.com/kubernetes/kubernetes/staging/src/k8s.io/client-go v0.0.0-20250724145648-d21da29c9ec4 h1:CY5Om06nF60Ml0GgQRvnwRvKJrxQi2VEzs/h6APBiSs= +github.com/kubernetes/kubernetes/staging/src/k8s.io/client-go v0.0.0-20250724145648-d21da29c9ec4/go.mod h1:8D4lk3MNioSJsWCThKJdKnMBLOkSBnI++8BV8LkI3yg= +github.com/kubernetes/kubernetes/staging/src/k8s.io/dynamic-resource-allocation v0.0.0-20250724145648-d21da29c9ec4 h1:WoDNAQXGufvcq9ukr9n3S009d2G7LlVH8mJhGqSShO8= +github.com/kubernetes/kubernetes/staging/src/k8s.io/dynamic-resource-allocation v0.0.0-20250724145648-d21da29c9ec4/go.mod h1:GKBfW4kFyslWq9aNU4SX+5+8xGusVxHmZ1Ulkxvk3MU= +github.com/kubernetes/kubernetes/staging/src/k8s.io/kubelet v0.0.0-20250724145648-d21da29c9ec4 h1:V71jGHQ86uDxuuuRGuzFeC7hfZoeUgNM3wIhoAhVk5I= +github.com/kubernetes/kubernetes/staging/src/k8s.io/kubelet v0.0.0-20250724145648-d21da29c9ec4/go.mod h1:GdHNOq3qgD1wFDv3sp/fw+bzEr/PDst+AM7HBOcZcn8= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= @@ -116,8 +125,9 @@ github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTa github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8= +github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM= @@ -203,6 +213,10 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= +go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -274,34 +288,23 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.33.3 h1:SRd5t//hhkI1buzxb288fy2xvjubstenEKL9K51KBI8= -k8s.io/api v0.33.3/go.mod h1:01Y/iLUjNBM3TAvypct7DIj0M0NIZc+PzAHCIo0CYGE= -k8s.io/apimachinery v0.33.3 h1:4ZSrmNa0c/ZpZJhAgRdcsFcZOw1PQU1bALVQ0B3I5LA= -k8s.io/apimachinery v0.33.3/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM= -k8s.io/client-go v0.33.3 h1:M5AfDnKfYmVJif92ngN532gFqakcGi6RvaOF16efrpA= -k8s.io/client-go v0.33.3/go.mod h1:luqKBQggEf3shbxHY4uVENAxrDISLOarxpTKMiUuujg= k8s.io/cloud-provider-gcp v0.0.0-20250326051131-7056e3facd39 h1:2m5DoDX46TPMmpcLRzrOWdBqouWChgbp4F/qlf/lIGc= k8s.io/cloud-provider-gcp v0.0.0-20250326051131-7056e3facd39/go.mod h1:NZrMafedcWXEFDubORCpHuWMp8cUS1TItObinH7vpwg= -k8s.io/component-helpers v0.33.3 h1:fjWVORSQfI0WKzPeIFSju/gMD9sybwXBJ7oPbqQu6eM= -k8s.io/component-helpers v0.33.3/go.mod h1:7iwv+Y9Guw6X4RrnNQOyQlXcvJrVjPveHVqUA5dm31c= -k8s.io/cri-api v0.33.3 h1:aQvK3UxsaVMul4z71lOiblMHdhw9ROaw3Cgg15xDrD4= -k8s.io/cri-api v0.33.3/go.mod h1:OLQvT45OpIA+tv91ZrpuFIGY+Y2Ho23poS7n115Aocs= -k8s.io/dynamic-resource-allocation v0.33.3 h1:NeWzn5mkDjyHmxRmVgEBi4qA5b/r7Ie2jqcR4t21Z+Q= -k8s.io/dynamic-resource-allocation v0.33.3/go.mod h1:YU6axYSVf1vC2OnPB8PjG5KipqoxyAKUGXB7HvRxvTk= +k8s.io/component-helpers v0.34.0-beta.0 h1:VtrSd4nRzYbHSr6hryNvIojiDOjf5MbjAWjyjGBjFjY= +k8s.io/component-helpers v0.34.0-beta.0/go.mod h1:H+zgzhEnCsKoOzb9PwRw5Ef1cv+cesDucZdjllYeVeM= +k8s.io/cri-api v0.34.0-beta.0 h1:m40PvwDyITXFK7T/sGb5VwWVc2hc8uuUOYU/KCkUzk8= +k8s.io/cri-api v0.34.0-beta.0/go.mod h1:4qVUjidMg7/Z9YGZpqIDygbkPWkg3mkS1PvOx/kpHTE= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20250610211856-8b98d1ed966a h1:ZV3Zr+/7s7aVbjNGICQt+ppKWsF1tehxggNfbM7XnG8= -k8s.io/kube-openapi v0.0.0-20250610211856-8b98d1ed966a/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8= -k8s.io/kubelet v0.33.3 h1:Cvy8+7Lq9saZds2ib7YBXbKvkMMJu3f5mzucmhSIJno= -k8s.io/kubelet v0.33.3/go.mod h1:Q1Cfr6VQq1m9v9XsE/mDmhTxPdN6NPU6Ug0e6mAqi58= +k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA= +k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b/go.mod h1:UZ2yyWbFTpuhSbFhv24aGNOdoRdJZgsIObGBUaYVsts= k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y= k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE= sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= -sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= -sigs.k8s.io/structured-merge-diff/v4 v4.7.0 h1:qPeWmscJcXP0snki5IYF79Z8xrl8ETFxgMd7wez1XkI= -sigs.k8s.io/structured-merge-diff/v4 v4.7.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps= -sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= -sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= +sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco= +sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE= +sigs.k8s.io/yaml v1.5.0 h1:M10b2U7aEUY6hRtU870n2VTPgR5RZiL/I6Lcc2F4NUQ= +sigs.k8s.io/yaml v1.5.0/go.mod h1:wZs27Rbxoai4C0f8/9urLZtZtF3avA3gKvGyPdDqTO4= diff --git a/pkg/cloudprovider/gce/gce.go b/pkg/cloudprovider/gce/gce.go index d2bc9902..50f867c4 100644 --- a/pkg/cloudprovider/gce/gce.go +++ b/pkg/cloudprovider/gce/gce.go @@ -29,7 +29,7 @@ import ( "k8s.io/klog/v2" "github.com/google/dranet/pkg/cloudprovider" - resourceapi "k8s.io/api/resource/v1beta1" + resourceapi "k8s.io/api/resource/v1" ) // GPUDirectSupport represents the type of GPUDirect support for a given machine type. diff --git a/pkg/driver/dra_hooks.go b/pkg/driver/dra_hooks.go index 1c3cc141..018380b1 100644 --- a/pkg/driver/dra_hooks.go +++ b/pkg/driver/dra_hooks.go @@ -31,8 +31,9 @@ import ( "github.com/vishvananda/netlink" "golang.org/x/sys/unix" - resourceapi "k8s.io/api/resource/v1beta1" + resourceapi "k8s.io/api/resource/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/dynamic-resource-allocation/kubeletplugin" "k8s.io/dynamic-resource-allocation/resourceslice" @@ -340,3 +341,9 @@ func (np *NetworkDriver) unprepareResourceClaim(_ context.Context, claim kubelet np.podConfigStore.DeleteClaim(claim.NamespacedName) return nil } + +func (np *NetworkDriver) HandleError(ctx context.Context, err error, msg string) { + // For now we just follow the advice documented in the DRAPlugin API docs. + // See: https://pkg.go.dev/k8s.io/apimachinery/pkg/util/runtime#HandleErrorWithContext + runtime.HandleErrorWithContext(ctx, err, msg) +} diff --git a/pkg/driver/hostdevice.go b/pkg/driver/hostdevice.go index cb6b7b18..48bc3dab 100644 --- a/pkg/driver/hostdevice.go +++ b/pkg/driver/hostdevice.go @@ -28,7 +28,7 @@ import ( "github.com/vishvananda/netns" "golang.org/x/sys/unix" - resourceapi "k8s.io/api/resource/v1beta1" + resourceapi "k8s.io/api/resource/v1" "k8s.io/klog/v2" ) diff --git a/pkg/driver/nri_hooks.go b/pkg/driver/nri_hooks.go index 8f21cc3e..0c1ea27b 100644 --- a/pkg/driver/nri_hooks.go +++ b/pkg/driver/nri_hooks.go @@ -28,7 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" metav1apply "k8s.io/client-go/applyconfigurations/meta/v1" - resourceapply "k8s.io/client-go/applyconfigurations/resource/v1beta1" + resourceapply "k8s.io/client-go/applyconfigurations/resource/v1" "k8s.io/klog/v2" "k8s.io/utils/set" ) @@ -210,7 +210,7 @@ func (np *NetworkDriver) RunPodSandbox(ctx context.Context, pod *api.PodSandbox) go func() { ctxStatus, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() - _, err := np.kubeClient.ResourceV1beta1().ResourceClaims(claim.Namespace).ApplyStatus(ctxStatus, + _, err := np.kubeClient.ResourceV1().ResourceClaims(claim.Namespace).ApplyStatus(ctxStatus, resourceClaimApply, metav1.ApplyOptions{FieldManager: np.driverName, Force: true}, ) diff --git a/pkg/filter/filter.go b/pkg/filter/filter.go index 96447519..8723be48 100644 --- a/pkg/filter/filter.go +++ b/pkg/filter/filter.go @@ -20,18 +20,18 @@ import ( "github.com/google/cel-go/cel" celtypes "github.com/google/cel-go/common/types" - resourcev1beta1 "k8s.io/api/resource/v1beta1" + resourcev1 "k8s.io/api/resource/v1" "k8s.io/klog/v2" ) -func FilterDevices(celProgram cel.Program, devices []resourcev1beta1.Device) []resourcev1beta1.Device { +func FilterDevices(celProgram cel.Program, devices []resourcev1.Device) []resourcev1.Device { if celProgram == nil { return devices } // filter in place - var filteredDevices []resourcev1beta1.Device + var filteredDevices []resourcev1.Device for _, dev := range devices { - out, _, err := celProgram.Eval(map[string]interface{}{"attributes": dev.Basic.Attributes}) + out, _, err := celProgram.Eval(map[string]interface{}{"attributes": dev.Attributes}) if err != nil { klog.Infof("prg.Eval() failed: %v", err) filteredDevices = append(filteredDevices, dev) diff --git a/pkg/filter/filter_test.go b/pkg/filter/filter_test.go index 2c94aec2..c6ca36dc 100644 --- a/pkg/filter/filter_test.go +++ b/pkg/filter/filter_test.go @@ -22,7 +22,7 @@ import ( "github.com/google/cel-go/cel" "github.com/google/cel-go/ext" - resourcev1beta1 "k8s.io/api/resource/v1beta1" + resourcev1 "k8s.io/api/resource/v1" "k8s.io/utils/ptr" ) @@ -30,33 +30,29 @@ func Test_filterDevices(t *testing.T) { tests := []struct { name string celProgram cel.Program - devices []resourcev1beta1.Device + devices []resourcev1.Device expectedLength int }{ { name: "nil program", celProgram: nil, - devices: []resourcev1beta1.Device{{Name: "dev1"}}, + devices: []resourcev1.Device{{Name: "dev1"}}, expectedLength: 1, }, { name: "filter by attribute", celProgram: mustCompileCEL(t, `attributes["kind"].StringValue == "network"`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev1", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("network")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("network")}, }, }, { Name: "dev2", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, }, }, }, @@ -65,23 +61,20 @@ func Test_filterDevices(t *testing.T) { { name: "filter by multiple attributes", celProgram: mustCompileCEL(t, `attributes["kind"].StringValue == "network" && attributes["name"].StringValue == "eth0"`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev1", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("network")}, - "name": {StringValue: ptr.To("eth0")}, - }, + + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("network")}, + "name": {StringValue: ptr.To("eth0")}, }, }, { Name: "dev2", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - "name": {StringValue: ptr.To("eth1")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, + "name": {StringValue: ptr.To("eth1")}, }, }, }, @@ -90,25 +83,23 @@ func Test_filterDevices(t *testing.T) { { name: "not veth", celProgram: mustCompileCEL(t, `attributes["type"].StringValue != "veth"`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev1", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("network")}, - "name": {StringValue: ptr.To("eth0")}, - "type": {StringValue: ptr.To("veth")}, - }, + + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("network")}, + "name": {StringValue: ptr.To("eth0")}, + "type": {StringValue: ptr.To("veth")}, }, }, { Name: "dev2", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - "name": {StringValue: ptr.To("eth1")}, - "type": {StringValue: ptr.To("veth")}, - }, + + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, + "name": {StringValue: ptr.To("eth1")}, + "type": {StringValue: ptr.To("veth")}, }, }, }, @@ -117,27 +108,23 @@ func Test_filterDevices(t *testing.T) { { name: "not virtual", celProgram: mustCompileCEL(t, `attributes["virtual"].BoolValue`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev1", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("network")}, - "name": {StringValue: ptr.To("eth0")}, - "type": {StringValue: ptr.To("veth")}, - "virtual": {BoolValue: ptr.To(true)}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("network")}, + "name": {StringValue: ptr.To("eth0")}, + "type": {StringValue: ptr.To("veth")}, + "virtual": {BoolValue: ptr.To(true)}, }, }, { Name: "dev2", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - "name": {StringValue: ptr.To("eth1")}, - "type": {StringValue: ptr.To("veth")}, - "virtual": {BoolValue: ptr.To(true)}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, + "name": {StringValue: ptr.To("eth1")}, + "type": {StringValue: ptr.To("veth")}, + "virtual": {BoolValue: ptr.To(true)}, }, }, }, @@ -146,27 +133,23 @@ func Test_filterDevices(t *testing.T) { { name: "empty devices", celProgram: mustCompileCEL(t, `attributes["kind"].StringValue == "network"`), - devices: []resourcev1beta1.Device{}, + devices: []resourcev1.Device{}, expectedLength: 0, }, { name: "all devices filtered", celProgram: mustCompileCEL(t, `attributes["kind"].StringValue == "network"`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev1", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, }, }, { Name: "dev2", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, }, }, }, @@ -175,21 +158,17 @@ func Test_filterDevices(t *testing.T) { { name: "no filter", celProgram: mustCompileCEL(t, `true`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev1", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("rdma")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("rdma")}, }, }, { Name: "dev2", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "kind": {StringValue: ptr.To("network")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "kind": {StringValue: ptr.To("network")}, }, }, }, @@ -198,29 +177,23 @@ func Test_filterDevices(t *testing.T) { { name: "eval error - division by zero", celProgram: mustCompileCEL(t, `(1 / attributes["divisor"].IntValue) == 1`), // Program is valid, but data can cause eval error - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev_error_div_zero", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "divisor": {IntValue: ptr.To[int64](0)}, // Causes division by zero during Eval - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "divisor": {IntValue: ptr.To[int64](0)}, // Causes division by zero during Eval }, }, { Name: "dev_no_error_eval_false", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "divisor": {IntValue: ptr.To[int64](2)}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "divisor": {IntValue: ptr.To[int64](2)}, }, }, { Name: "dev_no_error_eval_true", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "divisor": {IntValue: ptr.To[int64](1)}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "divisor": {IntValue: ptr.To[int64](1)}, }, }, }, @@ -229,29 +202,23 @@ func Test_filterDevices(t *testing.T) { { name: "eval error - no such key", celProgram: mustCompileCEL(t, `attributes["dra.net/type"].StringValue != "veth"`), - devices: []resourcev1beta1.Device{ + devices: []resourcev1.Device{ { Name: "dev_missing_key", // This device will cause "no such key: dra.net/type" - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - "some_other_key": {StringValue: ptr.To("value")}, - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + "some_other_key": {StringValue: ptr.To("value")}, }, }, { Name: "dev_key_present_eval_true", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - resourcev1beta1.QualifiedName("dra.net/type"): {StringValue: ptr.To("eth0")}, // != "veth" is true - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + resourcev1.QualifiedName("dra.net/type"): {StringValue: ptr.To("eth0")}, // != "veth" is true }, }, { Name: "dev_key_present_eval_false", - Basic: &resourcev1beta1.BasicDevice{ - Attributes: map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceAttribute{ - resourcev1beta1.QualifiedName("dra.net/type"): {StringValue: ptr.To("veth")}, // != "veth" is false - }, + Attributes: map[resourcev1.QualifiedName]resourcev1.DeviceAttribute{ + resourcev1.QualifiedName("dra.net/type"): {StringValue: ptr.To("veth")}, // != "veth" is false }, }, }, @@ -273,9 +240,9 @@ func mustCompileCEL(t *testing.T, expression string) cel.Program { t.Helper() env, err := cel.NewEnv( ext.NativeTypes( - reflect.ValueOf(resourcev1beta1.DeviceAttribute{}), + reflect.ValueOf(resourcev1.DeviceAttribute{}), ), - cel.Variable("attributes", cel.MapType(cel.StringType, cel.ObjectType("v1beta1.DeviceAttribute"))), + cel.Variable("attributes", cel.MapType(cel.StringType, cel.ObjectType("v1.DeviceAttribute"))), ) if err != nil { t.Fatalf("error creating CEL environment: %v", err) diff --git a/pkg/inventory/cloud.go b/pkg/inventory/cloud.go index eeae4034..51f27c8e 100644 --- a/pkg/inventory/cloud.go +++ b/pkg/inventory/cloud.go @@ -26,7 +26,7 @@ import ( "github.com/google/dranet/pkg/cloudprovider" "github.com/google/dranet/pkg/cloudprovider/gce" - resourceapi "k8s.io/api/resource/v1beta1" + resourceapi "k8s.io/api/resource/v1" ) // getInstanceProperties get the instace properties and stores them in a global variable to be used in discovery diff --git a/pkg/inventory/cloud_test.go b/pkg/inventory/cloud_test.go index 02e5f040..a06f1e9a 100644 --- a/pkg/inventory/cloud_test.go +++ b/pkg/inventory/cloud_test.go @@ -21,7 +21,7 @@ import ( "github.com/google/dranet/pkg/cloudprovider" "github.com/google/go-cmp/cmp" - resourceapi "k8s.io/api/resource/v1beta1" + resourceapi "k8s.io/api/resource/v1" "k8s.io/utils/ptr" ) diff --git a/pkg/inventory/db.go b/pkg/inventory/db.go index af79724e..b2937e3d 100644 --- a/pkg/inventory/db.go +++ b/pkg/inventory/db.go @@ -30,8 +30,9 @@ import ( "github.com/vishvananda/netlink" "github.com/vishvananda/netns" "golang.org/x/time/rate" - resourceapi "k8s.io/api/resource/v1beta1" + resourceapi "k8s.io/api/resource/v1" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/dynamic-resource-allocation/deviceattribute" "k8s.io/klog/v2" "k8s.io/utils/ptr" ) @@ -202,15 +203,13 @@ func (db *DB) GetResources(ctx context.Context) <-chan []resourceapi.Device { func (db *DB) netdevToDRAdev(link netlink.Link) (*resourceapi.Device, error) { ifName := link.Attrs().Name device := resourceapi.Device{ - Basic: &resourceapi.BasicDevice{ - Attributes: make(map[resourceapi.QualifiedName]resourceapi.DeviceAttribute), - Capacity: make(map[resourceapi.QualifiedName]resourceapi.DeviceCapacity), - }, + Attributes: make(map[resourceapi.QualifiedName]resourceapi.DeviceAttribute), + Capacity: make(map[resourceapi.QualifiedName]resourceapi.DeviceCapacity), } // Set the device name. It will be normalized only if necessary. device.Name = names.SetDeviceName(ifName) // expose the real interface name as an attribute in case it is normalized. - device.Basic.Attributes["dra.net/ifName"] = resourceapi.DeviceAttribute{StringValue: &ifName} + device.Attributes["dra.net/ifName"] = resourceapi.DeviceAttribute{StringValue: &ifName} linkType := link.Type() linkAttrs := link.Attrs() @@ -218,7 +217,7 @@ func (db *DB) netdevToDRAdev(link netlink.Link) (*resourceapi.Device, error) { // identify the namespace holding the link as the other end of a veth pair netnsid := link.Attrs().NetNsID if podName := db.GetPodName(netnsid); podName != "" { - device.Basic.Attributes["dra.net/pod"] = resourceapi.DeviceAttribute{StringValue: &podName} + device.Attributes["dra.net/pod"] = resourceapi.DeviceAttribute{StringValue: &podName} } v4 := sets.Set[string]{} @@ -236,76 +235,73 @@ func (db *DB) netdevToDRAdev(link netlink.Link) (*resourceapi.Device, error) { } } if v4.Len() > 0 { - device.Basic.Attributes["dra.net/ipv4"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(v4.UnsortedList(), ","))} + device.Attributes["dra.net/ipv4"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(v4.UnsortedList(), ","))} } if v6.Len() > 0 { - device.Basic.Attributes["dra.net/ipv6"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(v6.UnsortedList(), ","))} + device.Attributes["dra.net/ipv6"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(v6.UnsortedList(), ","))} } mac := link.Attrs().HardwareAddr.String() - device.Basic.Attributes["dra.net/mac"] = resourceapi.DeviceAttribute{StringValue: &mac} + device.Attributes["dra.net/mac"] = resourceapi.DeviceAttribute{StringValue: &mac} mtu := int64(link.Attrs().MTU) - device.Basic.Attributes["dra.net/mtu"] = resourceapi.DeviceAttribute{IntValue: &mtu} + device.Attributes["dra.net/mtu"] = resourceapi.DeviceAttribute{IntValue: &mtu} } - device.Basic.Attributes["dra.net/encapsulation"] = resourceapi.DeviceAttribute{StringValue: &linkAttrs.EncapType} + device.Attributes["dra.net/encapsulation"] = resourceapi.DeviceAttribute{StringValue: &linkAttrs.EncapType} operState := linkAttrs.OperState.String() - device.Basic.Attributes["dra.net/state"] = resourceapi.DeviceAttribute{StringValue: &operState} - device.Basic.Attributes["dra.net/alias"] = resourceapi.DeviceAttribute{StringValue: &linkAttrs.Alias} - device.Basic.Attributes["dra.net/type"] = resourceapi.DeviceAttribute{StringValue: &linkType} + device.Attributes["dra.net/state"] = resourceapi.DeviceAttribute{StringValue: &operState} + device.Attributes["dra.net/alias"] = resourceapi.DeviceAttribute{StringValue: &linkAttrs.Alias} + device.Attributes["dra.net/type"] = resourceapi.DeviceAttribute{StringValue: &linkType} // Get eBPF properties from the interface using the legacy tc hooks isEbpf := false filterNames, ok := getTcFilters(link) if ok { isEbpf = true - device.Basic.Attributes["dra.net/tcFilterNames"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(filterNames, ","))} + device.Attributes["dra.net/tcFilterNames"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(filterNames, ","))} } // Get eBPF properties from the interface using the tcx hooks programNames, ok := getTcxFilters(link) if ok { isEbpf = true - device.Basic.Attributes["dra.net/tcxProgramNames"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(programNames, ","))} + device.Attributes["dra.net/tcxProgramNames"] = resourceapi.DeviceAttribute{StringValue: ptr.To(strings.Join(programNames, ","))} } - device.Basic.Attributes["dra.net/ebpf"] = resourceapi.DeviceAttribute{BoolValue: &isEbpf} + device.Attributes["dra.net/ebpf"] = resourceapi.DeviceAttribute{BoolValue: &isEbpf} isRDMA := rdmamap.IsRDmaDeviceForNetdevice(ifName) - device.Basic.Attributes["dra.net/rdma"] = resourceapi.DeviceAttribute{BoolValue: &isRDMA} + device.Attributes["dra.net/rdma"] = resourceapi.DeviceAttribute{BoolValue: &isRDMA} // from https://github.com/k8snetworkplumbingwg/sriov-network-device-plugin/blob/ed1c14dd4c313c7dd9fe4730a60358fbeffbfdd4/pkg/netdevice/netDeviceProvider.go#L99 isSRIOV := sriovTotalVFs(ifName) > 0 - device.Basic.Attributes["dra.net/sriov"] = resourceapi.DeviceAttribute{BoolValue: &isSRIOV} + device.Attributes["dra.net/sriov"] = resourceapi.DeviceAttribute{BoolValue: &isSRIOV} if isSRIOV { vfs := int64(sriovNumVFs(ifName)) - device.Basic.Attributes["dra.net/sriovVfs"] = resourceapi.DeviceAttribute{IntValue: &vfs} + device.Attributes["dra.net/sriovVfs"] = resourceapi.DeviceAttribute{IntValue: &vfs} } if isVirtual(ifName, sysnetPath) { - device.Basic.Attributes["dra.net/virtual"] = resourceapi.DeviceAttribute{BoolValue: ptr.To(true)} + device.Attributes["dra.net/virtual"] = resourceapi.DeviceAttribute{BoolValue: ptr.To(true)} } else { - addPCIAttributes(device.Basic, ifName, sysnetPath) + addPCIAttributes(&device, ifName, sysnetPath) } mac := link.Attrs().HardwareAddr.String() for name, attribute := range getProviderAttributes(mac, db.instance) { - device.Basic.Attributes[name] = attribute + device.Attributes[name] = attribute } return &device, nil } -func addPCIAttributes(device *resourceapi.BasicDevice, ifName string, path string) { +func addPCIAttributes(device *resourceapi.Device, ifName string, path string) { device.Attributes["dra.net/virtual"] = resourceapi.DeviceAttribute{BoolValue: ptr.To(false)} - root, err := bdfRoot(ifName, path) - if err == nil { - if root.domain != "" && root.bus != "" { - // standardized attribute for all dra drivers - // ref: https://github.com/kubernetes/enhancements/pull/5316 - pcieRoot := fmt.Sprintf("pci%s:%s", root.domain, root.bus) - device.Attributes["resource.kubernetes.io/pcieRoot"] = resourceapi.DeviceAttribute{StringValue: &pcieRoot} - } + address, err := bdfAddress(ifName, path) + if err != nil { + klog.Infof("Could not get bdf address : %v", err) } else { - klog.Infof("could not get pci root : %v", err) + if err := setPciRootAttr(device, address); err != nil { + klog.Infof("Could not get pci root attribute : %v", err) + } } entry, err := ids(ifName, path) @@ -328,3 +324,12 @@ func addPCIAttributes(device *resourceapi.BasicDevice, ifName string, path strin device.Attributes["dra.net/numaNode"] = resourceapi.DeviceAttribute{IntValue: &numa} } } + +func setPciRootAttr(device *resourceapi.Device, address *pciAddress) error { + pcieRootAttr, err := deviceattribute.GetPCIeRootAttributeByPCIBusID(address.bus) + if err != nil { + return err + } + device.Attributes[pcieRootAttr.Name] = pcieRootAttr.Value + return nil +} diff --git a/pkg/inventory/sysfs.go b/pkg/inventory/sysfs.go index 1bacecdc..e7fddda6 100644 --- a/pkg/inventory/sysfs.go +++ b/pkg/inventory/sysfs.go @@ -174,28 +174,6 @@ func bdfAddress(ifName string, path string) (*pciAddress, error) { return address, nil } -// Obtain the root of the pci device for the interface. -// TODO(@michaelasp): Change this to use k8s helper function when available for consistency with other DRA solutions. -func bdfRoot(ifName, path string) (*pciRoot, error) { - root := &pciRoot{} - - sysfsPath := realpath(ifName, path) - bfd := strings.Split(sysfsPath, "/") - if len(bfd) < 5 { - return nil, fmt.Errorf("could not find corresponding PCI address: %v", bfd) - } - klog.V(4).Infof("pci root: %s", bfd[3]) - rootString := strings.Split(bfd[3], ":") - switch len(rootString) { - case 2: - root.domain = strings.TrimPrefix(rootString[0], "pci") - root.bus = rootString[1] - default: - return nil, fmt.Errorf("could not find corresponding PCI root: %v", rootString) - } - return root, nil -} - func ids(ifName string, path string) (*pcidb.Entry, error) { // PCI data var device, subsystemVendor, subsystemDevice []byte diff --git a/tests/setup_suite.bash b/tests/setup_suite.bash index 148cef1f..6a86a434 100644 --- a/tests/setup_suite.bash +++ b/tests/setup_suite.bash @@ -10,10 +10,16 @@ function setup_suite { # Build the image docker build -t "$IMAGE_NAME":test -f Dockerfile "$BATS_TEST_DIRNAME"/.. --load + # Build the kind image, needed for newest GA APIs + revision=$(curl --fail --silent --show-error --location https://dl.k8s.io/ci/fast/latest-fast.txt) + kind_node_source="https://dl.k8s.io/ci/fast/$revision/kubernetes-server-linux-amd64.tar.gz" + kind build node-image --image=dra/node:latest "${kind_node_source}" + mkdir -p _artifacts rm -rf _artifacts/* # create cluster kind create cluster \ + --image dra/node:latest \ --name $CLUSTER_NAME \ -v7 --wait 1m --retain \ --config="$BATS_TEST_DIRNAME"/../kind.yaml