Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: use resourcegen tool for coordinator.yaml #300

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
katexochen marked this conversation as resolved.
Show resolved Hide resolved
katexochen marked this conversation as resolved.
Show resolved Hide resolved
coordinator := Coordinator("").DeploymentApplyConfiguration
katexochen marked this conversation as resolved.
Show resolved Hide resolved
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