|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha4 |
| 18 | + |
| 19 | +import ( |
| 20 | + context "context" |
| 21 | + fmt "fmt" |
| 22 | + |
| 23 | + grpc "google.golang.org/grpc" |
| 24 | + "k8s.io/apimachinery/pkg/runtime" |
| 25 | + "k8s.io/kubelet/pkg/apis/dra/v1beta1" |
| 26 | +) |
| 27 | + |
| 28 | +var ( |
| 29 | + localSchemeBuilder runtime.SchemeBuilder |
| 30 | + AddToScheme = localSchemeBuilder.AddToScheme |
| 31 | +) |
| 32 | + |
| 33 | +// V1Beta1ServerWrapper implements the [NodeServer] interface by wrapping a [v1beta1.DRAPluginServer]. |
| 34 | +type V1Beta1ServerWrapper struct { |
| 35 | + v1beta1.DRAPluginServer |
| 36 | +} |
| 37 | + |
| 38 | +var _ NodeServer = V1Beta1ServerWrapper{} |
| 39 | + |
| 40 | +func (w V1Beta1ServerWrapper) NodePrepareResources(ctx context.Context, req *NodePrepareResourcesRequest) (*NodePrepareResourcesResponse, error) { |
| 41 | + var convertedReq v1beta1.NodePrepareResourcesRequest |
| 42 | + if err := Convert_v1alpha4_NodePrepareResourcesRequest_To_v1beta1_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 43 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1alpha4 to v1beta1: %w", err) |
| 44 | + } |
| 45 | + resp, err := w.DRAPluginServer.NodePrepareResources(ctx, &convertedReq) |
| 46 | + if err != nil { |
| 47 | + return nil, err |
| 48 | + } |
| 49 | + var convertedResp NodePrepareResourcesResponse |
| 50 | + if err := Convert_v1beta1_NodePrepareResourcesResponse_To_v1alpha4_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 51 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1beta1 to v1alpha4: %w", err) |
| 52 | + } |
| 53 | + return &convertedResp, nil |
| 54 | +} |
| 55 | + |
| 56 | +func (w V1Beta1ServerWrapper) NodeUnprepareResources(ctx context.Context, req *NodeUnprepareResourcesRequest) (*NodeUnprepareResourcesResponse, error) { |
| 57 | + var convertedReq v1beta1.NodeUnprepareResourcesRequest |
| 58 | + if err := Convert_v1alpha4_NodeUnprepareResourcesRequest_To_v1beta1_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 59 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1alpha4 to v1beta1: %w", err) |
| 60 | + } |
| 61 | + resp, err := w.DRAPluginServer.NodeUnprepareResources(ctx, &convertedReq) |
| 62 | + if err != nil { |
| 63 | + return nil, err |
| 64 | + } |
| 65 | + var convertedResp NodeUnprepareResourcesResponse |
| 66 | + if err := Convert_v1beta1_NodeUnprepareResourcesResponse_To_v1alpha4_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 67 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1beta1 to v1alpha4: %w", err) |
| 68 | + } |
| 69 | + return &convertedResp, nil |
| 70 | +} |
| 71 | + |
| 72 | +// V1Alpha4ServerWrapper implements the [v1beta1.DRAPluginServer] interface by wrapping a [NodeServer]. |
| 73 | +type V1Alpha4ServerWrapper struct { |
| 74 | + NodeServer |
| 75 | +} |
| 76 | + |
| 77 | +var _ v1beta1.DRAPluginServer = V1Alpha4ServerWrapper{} |
| 78 | + |
| 79 | +func (w V1Alpha4ServerWrapper) NodePrepareResources(ctx context.Context, req *v1beta1.NodePrepareResourcesRequest) (*v1beta1.NodePrepareResourcesResponse, error) { |
| 80 | + var convertedReq NodePrepareResourcesRequest |
| 81 | + if err := Convert_v1beta1_NodePrepareResourcesRequest_To_v1alpha4_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 82 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1beta1 to v1alpha4: %w", err) |
| 83 | + } |
| 84 | + resp, err := w.NodeServer.NodePrepareResources(ctx, &convertedReq) |
| 85 | + if err != nil { |
| 86 | + return nil, err |
| 87 | + } |
| 88 | + var convertedResp v1beta1.NodePrepareResourcesResponse |
| 89 | + if err := Convert_v1alpha4_NodePrepareResourcesResponse_To_v1beta1_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 90 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1alpha4 to v1beta1: %w", err) |
| 91 | + } |
| 92 | + return &convertedResp, nil |
| 93 | +} |
| 94 | + |
| 95 | +func (w V1Alpha4ServerWrapper) NodeUnprepareResources(ctx context.Context, req *v1beta1.NodeUnprepareResourcesRequest) (*v1beta1.NodeUnprepareResourcesResponse, error) { |
| 96 | + var convertedReq NodeUnprepareResourcesRequest |
| 97 | + if err := Convert_v1beta1_NodeUnprepareResourcesRequest_To_v1alpha4_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 98 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1beta1 to v1alpha4: %w", err) |
| 99 | + } |
| 100 | + resp, err := w.NodeServer.NodeUnprepareResources(ctx, &convertedReq) |
| 101 | + if err != nil { |
| 102 | + return nil, err |
| 103 | + } |
| 104 | + var convertedResp v1beta1.NodeUnprepareResourcesResponse |
| 105 | + if err := Convert_v1alpha4_NodeUnprepareResourcesResponse_To_v1beta1_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 106 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1alpha4 to v1beta1: %w", err) |
| 107 | + } |
| 108 | + return &convertedResp, nil |
| 109 | +} |
| 110 | + |
| 111 | +// V1Beta1ClientWrapper implements the [NodeClient] interface by wrapping a [v1beta1.DRAPluginClient]. |
| 112 | +type V1Beta1ClientWrapper struct { |
| 113 | + v1beta1.DRAPluginClient |
| 114 | +} |
| 115 | + |
| 116 | +var _ NodeClient = V1Beta1ClientWrapper{} |
| 117 | + |
| 118 | +func (w V1Beta1ClientWrapper) NodePrepareResources(ctx context.Context, req *NodePrepareResourcesRequest, options ...grpc.CallOption) (*NodePrepareResourcesResponse, error) { |
| 119 | + var convertedReq v1beta1.NodePrepareResourcesRequest |
| 120 | + if err := Convert_v1alpha4_NodePrepareResourcesRequest_To_v1beta1_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 121 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1alpha4 to v1beta1: %w", err) |
| 122 | + } |
| 123 | + resp, err := w.DRAPluginClient.NodePrepareResources(ctx, &convertedReq, options...) |
| 124 | + if err != nil { |
| 125 | + return nil, err |
| 126 | + } |
| 127 | + var convertedResp NodePrepareResourcesResponse |
| 128 | + if err := Convert_v1beta1_NodePrepareResourcesResponse_To_v1alpha4_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 129 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1beta1 to v1alpha4: %w", err) |
| 130 | + } |
| 131 | + return &convertedResp, nil |
| 132 | +} |
| 133 | + |
| 134 | +func (w V1Beta1ClientWrapper) NodeUnprepareResources(ctx context.Context, req *NodeUnprepareResourcesRequest, options ...grpc.CallOption) (*NodeUnprepareResourcesResponse, error) { |
| 135 | + var convertedReq v1beta1.NodeUnprepareResourcesRequest |
| 136 | + if err := Convert_v1alpha4_NodeUnprepareResourcesRequest_To_v1beta1_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 137 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1alpha4 to v1beta1: %w", err) |
| 138 | + } |
| 139 | + resp, err := w.DRAPluginClient.NodeUnprepareResources(ctx, &convertedReq, options...) |
| 140 | + if err != nil { |
| 141 | + return nil, err |
| 142 | + } |
| 143 | + var convertedResp NodeUnprepareResourcesResponse |
| 144 | + if err := Convert_v1beta1_NodeUnprepareResourcesResponse_To_v1alpha4_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 145 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1beta1 to v1alpha4: %w", err) |
| 146 | + } |
| 147 | + return &convertedResp, nil |
| 148 | +} |
| 149 | + |
| 150 | +// V1Alpha4ClientWrapper implements the [v1beta1.DRAPluginClient] interface by wrapping a [NodeClient]. |
| 151 | +type V1Alpha4ClientWrapper struct { |
| 152 | + NodeClient |
| 153 | +} |
| 154 | + |
| 155 | +var _ v1beta1.DRAPluginClient = V1Alpha4ClientWrapper{} |
| 156 | + |
| 157 | +func (w V1Alpha4ClientWrapper) NodePrepareResources(ctx context.Context, req *v1beta1.NodePrepareResourcesRequest, options ...grpc.CallOption) (*v1beta1.NodePrepareResourcesResponse, error) { |
| 158 | + var convertedReq NodePrepareResourcesRequest |
| 159 | + if err := Convert_v1beta1_NodePrepareResourcesRequest_To_v1alpha4_NodePrepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 160 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesRequest from v1beta1 to v1alpha4: %w", err) |
| 161 | + } |
| 162 | + resp, err := w.NodeClient.NodePrepareResources(ctx, &convertedReq, options...) |
| 163 | + if err != nil { |
| 164 | + return nil, err |
| 165 | + } |
| 166 | + var convertedResp v1beta1.NodePrepareResourcesResponse |
| 167 | + if err := Convert_v1alpha4_NodePrepareResourcesResponse_To_v1beta1_NodePrepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 168 | + return nil, fmt.Errorf("internal error converting NodePrepareResourcesResponse from v1alpha4 to v1beta1: %w", err) |
| 169 | + } |
| 170 | + return &convertedResp, nil |
| 171 | +} |
| 172 | + |
| 173 | +func (w V1Alpha4ClientWrapper) NodeUnprepareResources(ctx context.Context, req *v1beta1.NodeUnprepareResourcesRequest, options ...grpc.CallOption) (*v1beta1.NodeUnprepareResourcesResponse, error) { |
| 174 | + var convertedReq NodeUnprepareResourcesRequest |
| 175 | + if err := Convert_v1beta1_NodeUnprepareResourcesRequest_To_v1alpha4_NodeUnprepareResourcesRequest(req, &convertedReq, nil); err != nil { |
| 176 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesRequest from v1beta1 to v1alpha4: %w", err) |
| 177 | + } |
| 178 | + resp, err := w.NodeClient.NodeUnprepareResources(ctx, &convertedReq, options...) |
| 179 | + if err != nil { |
| 180 | + return nil, err |
| 181 | + } |
| 182 | + var convertedResp v1beta1.NodeUnprepareResourcesResponse |
| 183 | + if err := Convert_v1alpha4_NodeUnprepareResourcesResponse_To_v1beta1_NodeUnprepareResourcesResponse(resp, &convertedResp, nil); err != nil { |
| 184 | + return nil, fmt.Errorf("internal error converting NodeUnprepareResourcesResponse from v1alpha4 to v1beta1: %w", err) |
| 185 | + } |
| 186 | + return &convertedResp, nil |
| 187 | +} |
0 commit comments