Skip to content

Commit

Permalink
support preloading cache in pod evaluator (#3065)
Browse files Browse the repository at this point in the history
* support preloading cache in pod evaluator

* change yaml package and cancel context
  • Loading branch information
Mengqi Yu authored Apr 28, 2022
1 parent 4db5feb commit d32bf9a
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 72 deletions.
42 changes: 42 additions & 0 deletions porch/config/deploy/2-function-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,24 @@ spec:
- /server --config=/config.yaml --functions=/functions --pod-namespace=porch-fn-system --wrapper-server-image=gcr.io/example-google-project-id/porch-wrapper-server:latest
ports:
- containerPort: 9445
# Add grpc readiness probe to ensure the cache is ready
readinessProbe:
exec:
command:
- /grpc-health-probe
- -addr
- localhost:9445
resources:
requests:
memory: "64Mi"
cpu: "125m"
volumeMounts:
- mountPath: /pod-cache-config
name: pod-cache-config-volume
volumes:
- name: pod-cache-config-volume
configMap:
name: pod-cache-config

---
apiVersion: v1
Expand All @@ -63,3 +77,31 @@ spec:
- port: 9445
protocol: TCP
targetPort: 9445

---
apiVersion: v1
kind: ConfigMap
metadata:
name: pod-cache-config
namespace: porch-system
data:
pod-cache-config.yaml: |
gcr.io/kpt-fn/apply-replacements:v0.1.0: 30m
gcr.io/kpt-fn/apply-setters:v0.2.0: 30m
gcr.io/kpt-fn/create-setters:v0.1.0: 30m
gcr.io/kpt-fn/ensure-name-substring:v0.2.0: 30m
gcr.io/kpt-fn/gatekeeper:v0.2.1: 30m
gcr.io/kpt-fn/kubeval:v0.2.0: 30m
gcr.io/kpt-fn/search-replace:v0.2.0: 30m
gcr.io/kpt-fn/set-annotations:v0.1.4: 30m
gcr.io/kpt-fn/set-enforcement-action:v0.1.0: 30m
gcr.io/kpt-fn/set-image:v0.1.0: 30m
gcr.io/kpt-fn/set-labels:v0.1.5: 30m
gcr.io/kpt-fn/set-namespace:v0.3.4: 30m
gcr.io/kpt-fn/starlark:v0.4.2: 30m
gcr.io/kpt-fn/upsert-resource:v0.2.0: 30m
gcr.io/kpt-fn/enable-gcp-services:v0.1.0: 30m
gcr.io/kpt-fn/export-terraform:v0.1.0: 30m
gcr.io/kpt-fn/generate-folders:v0.1.1: 30m
gcr.io/kpt-fn/remove-local-config-resources:v0.1.0: 30m
gcr.io/kpt-fn/set-project-id:v0.2.0: 30m
5 changes: 4 additions & 1 deletion porch/func/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ FROM gcr.io/kpt-fn/upsert-resource:v0.2.0 as upsert-resource
FROM golang:1.17.6-alpine3.15 as builder
WORKDIR /go/src/github.com/GoogleContainerTools/kpt

RUN go install github.com/grpc-ecosystem/[email protected]
RUN cp $GOPATH/bin/grpc-health-probe /grpc-health-probe

COPY go.mod go.sum ./
COPY porch/go.mod porch/go.sum porch/
COPY porch/api/go.mod porch/api/go.sum porch/api/
Expand All @@ -52,7 +55,7 @@ COPY --from=set-namespace /usr/local/bin/function /functions/set-namesp
COPY --from=set-project-id /usr/local/bin/function /functions/set-project-id
COPY --from=starlark /usr/local/bin/star /functions/starlark
COPY --from=upsert-resource /usr/local/bin/function /functions/upsert-resource
COPY --from=builder /server /config.yaml /
COPY --from=builder /server /grpc-health-probe /config.yaml /

EXPOSE 9445/tcp
ENTRYPOINT [ "/server", "--config=/config.yaml", "--functions=/functions" ]
2 changes: 1 addition & 1 deletion porch/func/Dockerfile-wrapperserver
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY go.mod go.sum ./
COPY porch/go.mod porch/go.sum porch/
COPY porch/api/go.mod porch/api/go.sum porch/api/

RUN go install github.com/grpc-ecosystem/[email protected].8
RUN go install github.com/grpc-ecosystem/[email protected].11
COPY porch/func/ porch/func/
RUN cd porch/func ; go build -v -o /wrapper-server/wrapper-server ./wrapper-server
RUN cp $GOPATH/bin/grpc-health-probe /wrapper-server/
Expand Down
42 changes: 42 additions & 0 deletions porch/func/healthchecker/healthchecker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 Google LLC
//
// 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 healthchecker

import (
"context"

"google.golang.org/grpc/health/grpc_health_v1"
"k8s.io/klog/v2"
)

type HealthChecker struct{}

func NewHealthChecker() *HealthChecker {
return &HealthChecker{}
}

func (s *HealthChecker) Check(ctx context.Context, req *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error) {
klog.Info("Serving the Check request for health check")
return &grpc_health_v1.HealthCheckResponse{
Status: grpc_health_v1.HealthCheckResponse_SERVING,
}, nil
}

func (s *HealthChecker) Watch(req *grpc_health_v1.HealthCheckRequest, server grpc_health_v1.Health_WatchServer) error {
klog.Info("Serving the Watch request for health check")
return server.Send(&grpc_health_v1.HealthCheckResponse{
Status: grpc_health_v1.HealthCheckResponse_SERVING,
})
}
Loading

0 comments on commit d32bf9a

Please sign in to comment.