diff --git a/e2e/internal/kuberesource/parts.go b/e2e/internal/kuberesource/parts.go index 63c40dd765..34c7171e9c 100644 --- a/e2e/internal/kuberesource/parts.go +++ b/e2e/internal/kuberesource/parts.go @@ -3,6 +3,7 @@ package kuberesource import ( "strconv" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" applyappsv1 "k8s.io/client-go/applyconfigurations/apps/v1" applycorev1 "k8s.io/client-go/applyconfigurations/core/v1" @@ -120,7 +121,7 @@ func (c *CoordinatorConfig) GetDeploymentConfig() *DeploymentConfig { // ServiceForDeployment creates a service for a deployment by exposing the configured ports // of the deployment's first container. -func ServiceForDeployment(d *applyappsv1.DeploymentApplyConfiguration) *applycorev1.ServiceApplyConfiguration { +func ServiceForDeployment(d *applyappsv1.DeploymentApplyConfiguration, serviceType *corev1.ServiceType) *applycorev1.ServiceApplyConfiguration { selector := d.Spec.Selector.MatchLabels ports := d.Spec.Template.Spec.Containers[0].Ports @@ -128,6 +129,7 @@ func ServiceForDeployment(d *applyappsv1.DeploymentApplyConfiguration) *applycor WithSpec(ServiceSpec(). WithSelector(selector), ) + s.Spec.Type = serviceType for _, p := range ports { s.Spec.WithPorts( diff --git a/e2e/internal/kuberesource/resourcegen/main.go b/e2e/internal/kuberesource/resourcegen/main.go index 85baa6b27b..ad5849dbc5 100644 --- a/e2e/internal/kuberesource/resourcegen/main.go +++ b/e2e/internal/kuberesource/resourcegen/main.go @@ -20,6 +20,8 @@ func main() { var resources []any var err error switch set { + case "coordinator-release": + resources, err = kuberesource.CoordinatorRelease() case "simple": resources, err = kuberesource.Simple() case "openssl": diff --git a/e2e/internal/kuberesource/sets.go b/e2e/internal/kuberesource/sets.go index ed4462f174..02880320cf 100644 --- a/e2e/internal/kuberesource/sets.go +++ b/e2e/internal/kuberesource/sets.go @@ -1,6 +1,21 @@ package kuberesource -import "k8s.io/apimachinery/pkg/util/intstr" +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +func CoordinatorRelease() ([]any, error) { + coordinator := Coordinator("").DeploymentApplyConfiguration + coordinatorService := ServiceForDeployment(coordinator, toPtr(corev1.ServiceTypeLoadBalancer)) + + resources := []any{ + coordinator, + coordinatorService, + } + + return resources, nil +} // Simple returns a simple set of resources for testing. func Simple() ([]any, error) { @@ -8,7 +23,7 @@ func Simple() ([]any, error) { namespace := Namespace(ns) coordinator := Coordinator(ns).DeploymentApplyConfiguration - coordinatorService := ServiceForDeployment(coordinator) + coordinatorService := ServiceForDeployment(coordinator, nil) coordinatorForwarder := PortForwarder("coordinator", ns). WithListenPort(1313). WithForwardTarget("coordinator", 1313). @@ -57,7 +72,7 @@ func OpenSSL() ([]any, error) { ns := "edg-default" namespace := Namespace(ns) coordinator := Coordinator(ns).DeploymentApplyConfiguration - coordinatorService := ServiceForDeployment(coordinator) + coordinatorService := ServiceForDeployment(coordinator, nil) coordinatorForwarder := PortForwarder("coordinator", ns). WithListenPort(1313). WithForwardTarget("coordinator", 1313). @@ -102,7 +117,7 @@ func OpenSSL() ([]any, error) { return nil, err } - backendService := ServiceForDeployment(backend) + backendService := ServiceForDeployment(backend, nil) client := Deployment("openssl-client", ns). WithSpec(DeploymentSpec(). @@ -169,7 +184,7 @@ func OpenSSL() ([]any, error) { return nil, err } - frontendService := ServiceForDeployment(frontend) + frontendService := ServiceForDeployment(frontend, nil) portforwarderCoordinator := PortForwarder("coordinator", ns). WithListenPort(1313). @@ -197,3 +212,7 @@ func OpenSSL() ([]any, error) { return resources, nil } + +func toPtr[T any](v T) *T { + return &v +} diff --git a/packages/scripts.nix b/packages/scripts.nix index 0cf2f3bdb5..7b373f486b 100644 --- a/packages/scripts.nix +++ b/packages/scripts.nix @@ -149,6 +149,7 @@ with pkgs; runtimeInputs = [ yq-go genpolicy-msft + contrast ]; text = '' imageRef=$1 @@ -156,11 +157,9 @@ with pkgs; tmpdir=$(mktemp -d) trap 'rm -rf $tmpdir' EXIT - # TODO(burgerdev): consider a dedicated coordinator template instead of the simple one - yq < deployments/simple/coordinator.yml > "$tmpdir/coordinator.yml" \ - "del(.metadata.namespace) | - (select(.kind == \"Deployment\") | .spec.template.spec.containers[0].image) = \"$imageRef\" | - (select(.kind == \"Service\") | .spec.type) = \"LoadBalancer\" " + resourcegen coordinator-release "$tmpdir/coordinator_base.yml" + yq < "$tmpdir/coordinator_base.yml" > "$tmpdir/coordinator.yml" \ + "(select(.kind == \"Deployment\") | .spec.template.spec.containers[0].image) = \"$imageRef\"" pushd "$tmpdir" >/dev/null cp ${genpolicy-msft.rules-coordinator}/genpolicy-rules.rego rules.rego