Skip to content

Commit

Permalink
release: use resourcegen tool for coordinator.yaml
Browse files Browse the repository at this point in the history
Signed-off-by: Malte Poll <[email protected]>
Co-authored-by: Paul Meyer <[email protected]>
  • Loading branch information
malt3 and katexochen committed Apr 8, 2024
1 parent 08fa0a3 commit 5945f7a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
6 changes: 5 additions & 1 deletion e2e/internal/kuberesource/parts.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ func ServiceForDeployment(d *applyappsv1.DeploymentApplyConfiguration) *applycor
selector := d.Spec.Selector.MatchLabels
ports := d.Spec.Template.Spec.Containers[0].Ports

s := Service(*d.Name, *d.Namespace).
var ns string
if d.Namespace != nil {
ns = *d.Namespace
}
s := Service(*d.Name, ns).
WithSpec(ServiceSpec().
WithSelector(selector),
)
Expand Down
2 changes: 2 additions & 0 deletions e2e/internal/kuberesource/resourcegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
20 changes: 19 additions & 1 deletion e2e/internal/kuberesource/sets.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
package kuberesource

import "k8s.io/apimachinery/pkg/util/intstr"
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// CoordinatorRelease will generate the Coordinator deployment YAML that is published
// as release artifact with a pre-generated policy (which is not contained in this function).
func CoordinatorRelease() ([]any, error) {
coordinator := Coordinator("").DeploymentApplyConfiguration
coordinatorService := ServiceForDeployment(coordinator)
coordinatorService.Spec.WithType(corev1.ServiceTypeLoadBalancer)

resources := []any{
coordinator,
coordinatorService,
}

return resources, nil
}

// Simple returns a simple set of resources for testing.
func Simple() ([]any, error) {
Expand Down
12 changes: 10 additions & 2 deletions e2e/internal/kuberesource/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ type DeploymentConfig struct {

// Deployment creates a new DeploymentConfig.
func Deployment(name, namespace string) *DeploymentConfig {
return &DeploymentConfig{applyappsv1.Deployment(name, namespace)}
d := applyappsv1.Deployment(name, namespace)
if namespace == "" && d.ObjectMetaApplyConfiguration != nil {
d.ObjectMetaApplyConfiguration.Namespace = nil
}
return &DeploymentConfig{d}
}

// DeploymentSpecConfig wraps applyappsv1.DeploymentSpecApplyConfiguration.
Expand Down Expand Up @@ -175,7 +179,11 @@ type ServiceConfig struct {

// Service creates a new ServiceConfig.
func Service(name, namespace string) *ServiceConfig {
return &ServiceConfig{applycorev1.Service(name, namespace)}
s := applycorev1.Service(name, namespace)
if namespace == "" && s.ObjectMetaApplyConfiguration != nil {
s.ObjectMetaApplyConfiguration.Namespace = nil
}
return &ServiceConfig{s}
}

// ServiceSpecConfig wraps applycorev1.ServiceSpecApplyConfiguration.
Expand Down
9 changes: 4 additions & 5 deletions packages/scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,17 @@ with pkgs;
runtimeInputs = [
yq-go
genpolicy-msft
contrast
];
text = ''
imageRef=$1
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
Expand Down

0 comments on commit 5945f7a

Please sign in to comment.