Skip to content

Commit 09b80e1

Browse files
authored
Merge pull request #105 from awslabs/krocel
refactor: rename cel package alias from `scel` to `krocel`
2 parents a6738b4 + db26bc3 commit 09b80e1

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

internal/cel/ast/inspector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import (
1717
"fmt"
1818
"strings"
1919

20-
scel "github.com/awslabs/kro/internal/cel"
2120
"github.com/google/cel-go/cel"
2221
exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
22+
23+
krocel "github.com/awslabs/kro/internal/cel"
2324
)
2425

2526
// ResourceDependency represents a resource and its accessed path within a CEL expression.
@@ -117,7 +118,7 @@ func DefaultInspector(resources []string, functions []string) (*Inspector, error
117118
functionMap[function] = struct{}{}
118119
}
119120

120-
env, err := scel.DefaultEnvironment(scel.WithCustomDeclarations(declarations))
121+
env, err := krocel.DefaultEnvironment(krocel.WithCustomDeclarations(declarations))
121122
if err != nil {
122123
return nil, fmt.Errorf("failed to create CEL environment: %v", err)
123124
}

internal/graph/builder.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"k8s.io/client-go/rest"
3030

3131
"github.com/awslabs/kro/api/v1alpha1"
32-
scel "github.com/awslabs/kro/internal/cel"
32+
krocel "github.com/awslabs/kro/internal/cel"
3333
"github.com/awslabs/kro/internal/cel/ast"
3434
"github.com/awslabs/kro/internal/graph/crd"
3535
"github.com/awslabs/kro/internal/graph/dag"
@@ -356,7 +356,7 @@ func (b *Builder) buildDependencyGraph(
356356
// We also want to allow users to refer to the instance spec in their expressions.
357357
resourceNames = append(resourceNames, "schema")
358358

359-
env, err := scel.DefaultEnvironment(scel.WithResourceNames(resourceNames))
359+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames(resourceNames))
360360
if err != nil {
361361
return nil, fmt.Errorf("failed to create CEL environment: %w", err)
362362
}
@@ -465,7 +465,7 @@ func (b *Builder) buildInstanceResource(
465465
}
466466

467467
resourceNames := maps.Keys(resources)
468-
env, err := scel.DefaultEnvironment(scel.WithResourceNames(resourceNames))
468+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames(resourceNames))
469469
if err != nil {
470470
return nil, fmt.Errorf("failed to create CEL environment: %w", err)
471471
}
@@ -552,7 +552,7 @@ func buildStatusSchema(
552552
// Inspection of the CEL expressions to infer the types of the status fields.
553553
resourceNames := maps.Keys(resources)
554554

555-
env, err := scel.DefaultEnvironment(scel.WithResourceNames(resourceNames))
555+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames(resourceNames))
556556
if err != nil {
557557
return nil, nil, fmt.Errorf("failed to create CEL environment: %w", err)
558558
}
@@ -682,7 +682,7 @@ func validateResourceCELExpressions(resources map[string]*Resource, instance *Re
682682
resourceNames = append(resourceNames, "schema")
683683
conditionFieldNames := []string{"schema"}
684684

685-
env, err := scel.DefaultEnvironment(scel.WithResourceNames(resourceNames))
685+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames(resourceNames))
686686
if err != nil {
687687
return fmt.Errorf("failed to create CEL environment: %w", err)
688688
}
@@ -731,7 +731,7 @@ func validateResourceCELExpressions(resources map[string]*Resource, instance *Re
731731
// I would also suggest separating the dryRuns of readyWhenExpressions
732732
// and the resourceExpressions.
733733
for _, readyWhenExpression := range resource.readyWhenExpressions {
734-
fieldEnv, err := scel.DefaultEnvironment(scel.WithResourceNames([]string{resource.id}))
734+
fieldEnv, err := krocel.DefaultEnvironment(krocel.WithResourceNames([]string{resource.id}))
735735
if err != nil {
736736
return fmt.Errorf("failed to create CEL environment: %w", err)
737737
}
@@ -756,13 +756,13 @@ func validateResourceCELExpressions(resources map[string]*Resource, instance *Re
756756
if err != nil {
757757
return fmt.Errorf("failed to dry-run expression %s: %w", readyWhenExpression, err)
758758
}
759-
if !scel.IsBoolType(output) {
759+
if !krocel.IsBoolType(output) {
760760
return fmt.Errorf("output of readyWhen expression %s can only be of type bool", readyWhenExpression)
761761
}
762762
}
763763

764764
for _, includeWhenExpression := range resource.includeWhenExpressions {
765-
instanceEnv, err := scel.DefaultEnvironment(scel.WithResourceNames(resourceNames))
765+
instanceEnv, err := krocel.DefaultEnvironment(krocel.WithResourceNames(resourceNames))
766766
if err != nil {
767767
return fmt.Errorf("failed to create CEL environment: %w", err)
768768
}
@@ -786,7 +786,7 @@ func validateResourceCELExpressions(resources map[string]*Resource, instance *Re
786786
if err != nil {
787787
return fmt.Errorf("failed to dry-run expression %s: %w", includeWhenExpression, err)
788788
}
789-
if !scel.IsBoolType(output) {
789+
if !krocel.IsBoolType(output) {
790790
return fmt.Errorf("output of condition expression %s can only be of type bool", includeWhenExpression)
791791
}
792792
}

internal/graph/schema/conversion_cel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import (
1919
"github.com/google/cel-go/common/types/ref"
2020
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2121

22-
scel "github.com/awslabs/kro/internal/cel"
22+
krocel "github.com/awslabs/kro/internal/cel"
2323
)
2424

2525
// inferSchemaFromCELValue infers a JSONSchemaProps from a CEL value.
2626
func inferSchemaFromCELValue(val ref.Val) (*extv1.JSONSchemaProps, error) {
2727
if val == nil {
2828
return nil, fmt.Errorf("value is nil")
2929
}
30-
goRuntimeVal, err := scel.GoNativeType(val)
30+
goRuntimeVal, err := krocel.GoNativeType(val)
3131
if err != nil {
3232
return nil, fmt.Errorf("failed to convert CEL value to Go: %w", err)
3333
}

internal/runtime/runtime.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"golang.org/x/exp/maps"
2323
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2424

25-
scel "github.com/awslabs/kro/internal/cel"
25+
krocel "github.com/awslabs/kro/internal/cel"
2626
"github.com/awslabs/kro/internal/graph/variable"
2727
"github.com/awslabs/kro/internal/runtime/resolver"
2828
)
@@ -302,7 +302,7 @@ func (rt *ResourceGroupRuntime) resourceVariablesResolved(resource string) bool
302302
// depending only on the initial configuration. This function is usually
303303
// called once during runtime initialization to set up the baseline state
304304
func (rt *ResourceGroupRuntime) evaluateStaticVariables() error {
305-
env, err := scel.DefaultEnvironment(scel.WithResourceNames([]string{"schema"}))
305+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames([]string{"schema"}))
306306
if err != nil {
307307
return err
308308
}
@@ -346,7 +346,7 @@ func (rt *ResourceGroupRuntime) evaluateDynamicVariables() error {
346346
// and are resolved after all the dependencies are resolved.
347347

348348
resolvedResources := maps.Keys(rt.resolvedResources)
349-
env, err := scel.DefaultEnvironment(scel.WithResourceNames(resolvedResources))
349+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames(resolvedResources))
350350
if err != nil {
351351
return err
352352
}
@@ -474,7 +474,7 @@ func (rt *ResourceGroupRuntime) IsResourceReady(resourceID string) (bool, string
474474

475475
// we should not expect errors here since we already compiled it
476476
// in the dryRun
477-
env, err := scel.DefaultEnvironment(scel.WithResourceNames([]string{resourceID}))
477+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames([]string{resourceID}))
478478
if err != nil {
479479
return false, "", fmt.Errorf("failed creating new Environment: %w", err)
480480
}
@@ -530,7 +530,7 @@ func (rt *ResourceGroupRuntime) WantToCreateResource(resourceID string) (bool, e
530530

531531
// we should not expect errors here since we already compiled it
532532
// in the dryRun
533-
env, err := scel.DefaultEnvironment(scel.WithResourceNames([]string{"schema"}))
533+
env, err := krocel.DefaultEnvironment(krocel.WithResourceNames([]string{"schema"}))
534534
if err != nil {
535535
return false, nil
536536
}
@@ -572,7 +572,7 @@ func evaluateExpression(env *cel.Env, context map[string]interface{}, expression
572572
return nil, fmt.Errorf("failed evaluating expression %s: %w", expression, err)
573573
}
574574

575-
return scel.GoNativeType(val)
575+
return krocel.GoNativeType(val)
576576
}
577577

578578
// containsAllElements checks if all elements in the inner slice are present

internal/runtime/runtime_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2424
"k8s.io/apimachinery/pkg/runtime/schema"
2525

26-
scel "github.com/awslabs/kro/internal/cel"
26+
krocel "github.com/awslabs/kro/internal/cel"
2727
"github.com/awslabs/kro/internal/graph/variable"
2828
)
2929

@@ -2463,7 +2463,7 @@ func Test_areDependenciesIgnored(t *testing.T) {
24632463
}
24642464

24652465
func setupTestEnv(names []string) (*cel.Env, error) {
2466-
return scel.DefaultEnvironment(scel.WithResourceNames(names))
2466+
return krocel.DefaultEnvironment(krocel.WithResourceNames(names))
24672467
}
24682468

24692469
func Test_evaluateExpression(t *testing.T) {

0 commit comments

Comments
 (0)