Skip to content

Instantly share code, notes, and snippets.

@ihcsim
Created January 14, 2025 05:39
Show Gist options
  • Save ihcsim/3f48db3ec661718281c49c314fe7edef to your computer and use it in GitHub Desktop.
Save ihcsim/3f48db3ec661718281c49c314fe7edef to your computer and use it in GitHub Desktop.
// ForInput evaluates the compiled CEL expressions converting them into CELEvaluations
// errors per evaluation are returned on the Evaluation object
// runtimeCELCostBudget was added for testing purpose only. Callers should always use const RuntimeCELCostBudget from k8s.io/apiserver/pkg/apis/cel/config.go as input.
func (c *condition) ForInput(ctx context.Context, versionedAttr *admission.VersionedAttributes, request *admissionv1.AdmissionRequest, inputs OptionalVariableBindings, namespace *v1.Namespace, runtimeCELCostBudget int64) ([]EvaluationResult, int64, error) {
// ...
remainingBudget := runtimeCELCostBudget
for i, compilationResult := range c.compilationResults {
evaluations[i], remainingBudget, err = activation.Evaluate(ctx, compositionCtx, compilationResult, remainingBudget)
if err != nil {
return nil, -1, err
}
}
return evaluations, remainingBudget, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment