Skip to content

Commit 8c45fa1

Browse files
committed
Add peer fields to replace inlined non proto-message Kubernetes objects
1 parent 6ccebbb commit 8c45fa1

File tree

4 files changed

+607
-461
lines changed

4 files changed

+607
-461
lines changed

cluster-autoscaler/cloudprovider/externalgrpc/examples/external-grpc-cloud-provider-service/wrapper/wrapper.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"google.golang.org/grpc/codes"
2525
"google.golang.org/grpc/status"
2626
"google.golang.org/protobuf/types/known/anypb"
27+
2728
apiv1 "k8s.io/api/core/v1"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
@@ -148,9 +149,38 @@ func (w *Wrapper) PricingPodPrice(_ context.Context, req *protos.PricingPodPrice
148149
}
149150
return nil, err
150151
}
151-
reqPod := req.GetPod()
152-
reqStartTime := req.GetStartTime()
153-
reqEndTime := req.GetEndTime()
152+
153+
var reqPod *apiv1.Pod
154+
if podBytes := req.GetPodBytes(); podBytes != nil {
155+
// decode from opaque bytes into pod if set
156+
pod := &apiv1.Pod{}
157+
if err := pod.Unmarshal(podBytes); err != nil {
158+
return nil, err
159+
}
160+
reqPod = pod
161+
} else {
162+
// otherwise fallback to reading inlined pod
163+
reqPod = req.GetPod()
164+
}
165+
166+
var reqStartTime *metav1.Time
167+
if startTimestamp := req.GetStartTimestamp(); startTimestamp != nil {
168+
// read standard protobuf timestamp if set
169+
reqStartTime = &metav1.Time{Time: startTimestamp.AsTime()}
170+
} else {
171+
// otherwise fallback to reading metav1.Time
172+
reqStartTime = req.GetStartTime()
173+
}
174+
175+
var reqEndTime *metav1.Time
176+
if endTimestamp := req.GetEndTimestamp(); endTimestamp != nil {
177+
// read standard protobuf timestamp if set
178+
reqEndTime = &metav1.Time{Time: endTimestamp.AsTime()}
179+
} else {
180+
// otherwise fallback to reading metav1.Time
181+
reqEndTime = req.GetEndTime()
182+
}
183+
154184
if reqPod == nil || reqStartTime == nil || reqEndTime == nil {
155185
return nil, fmt.Errorf("request fields were nil")
156186
}

cluster-autoscaler/cloudprovider/externalgrpc/externalgrpc_cloud_provider.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"google.golang.org/grpc/codes"
3131
"google.golang.org/grpc/credentials"
3232
"google.golang.org/grpc/status"
33+
"google.golang.org/protobuf/types/known/timestamppb"
34+
3335
apiv1 "k8s.io/api/core/v1"
3436
"k8s.io/apimachinery/pkg/api/resource"
3537
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -162,6 +164,9 @@ func (m *pricingModel) NodePrice(node *apiv1.Node, startTime time.Time, endTime
162164
Node: externalGrpcNode(node),
163165
StartTime: &start,
164166
EndTime: &end,
167+
168+
StartTimestamp: timestamppb.New(startTime),
169+
EndTimestamp: timestamppb.New(endTime),
165170
})
166171
if err != nil {
167172
st, ok := status.FromError(err)
@@ -182,10 +187,20 @@ func (m *pricingModel) PodPrice(pod *apiv1.Pod, startTime time.Time, endTime tim
182187
klog.V(5).Infof("Performing gRPC call PricingPodPrice for pod %v", pod.Name)
183188
start := metav1.NewTime(startTime)
184189
end := metav1.NewTime(endTime)
190+
191+
podBytes, err := pod.Marshal()
192+
if err != nil {
193+
return 0, err
194+
}
195+
185196
res, err := m.client.PricingPodPrice(ctx, &protos.PricingPodPriceRequest{
186197
Pod: pod,
187198
StartTime: &start,
188199
EndTime: &end,
200+
201+
PodBytes: podBytes,
202+
StartTimestamp: timestamppb.New(startTime),
203+
EndTimestamp: timestamppb.New(endTime),
189204
})
190205
if err != nil {
191206
st, ok := status.FromError(err)

0 commit comments

Comments
 (0)