Skip to content

Commit

Permalink
Remove assumption that infra replicas default to 2
Browse files Browse the repository at this point in the history
Signed-off-by: Jed Lejosne <[email protected]>
  • Loading branch information
jean-edouard committed May 26, 2022
1 parent be28d3c commit 7942f32
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hack/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ conn_check_ipv4_address=${CONN_CHECK_IPV4_ADDRESS:-""}
conn_check_ipv6_address=${CONN_CHECK_IPV6_ADDRESS:-""}
conn_check_dns=${CONN_CHECK_DNS:-""}
migration_network_nic=${MIGRATION_NETWORK_NIC:-"eth1"}
infra_replicas=${KUBEVIRT_INFRA_REPLICAS:-2}
infra_replicas=${KUBEVIRT_INFRA_REPLICAS:-0}

# try to derive csv_version from docker tag. But it must start with x.y.z, without leading v
default_csv_version="${docker_tag/latest/0.0.0}"
Expand Down
4 changes: 2 additions & 2 deletions manifests/generated/kubevirt-cr.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ spec:
{{- end}}{{else}} []{{end}}
customizeComponents: {}
imagePullPolicy: {{.ImagePullPolicy}}
infra:
replicas: {{.InfraReplicas}}
infra:{{if .InfraReplicas}}
replicas: {{.InfraReplicas}}{{end}}
workloadUpdateStrategy: {}
8 changes: 2 additions & 6 deletions pkg/virt-operator/resource/generate/components/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"fmt"
"strings"

"kubevirt.io/kubevirt/pkg/virt-operator/util"

"kubevirt.io/api/flavor"

"kubevirt.io/api/migrations"
Expand Down Expand Up @@ -691,10 +689,8 @@ func NewKubeVirtCR(namespace string, pullPolicy corev1.PullPolicy, featureGates
}
}

if infraReplicas != util.DefaultInfraReplicas {
cr.Spec.Infra = &virtv1.ComponentConfig{
Replicas: &infraReplicas,
}
cr.Spec.Infra = &virtv1.ComponentConfig{
Replicas: &infraReplicas,
}

return cr
Expand Down
3 changes: 0 additions & 3 deletions pkg/virt-operator/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ const (
// #nosec 101, the variable is not holding any credential
// Prefix for env vars that will be passed along
PassthroughEnvPrefix = "KV_IO_EXTRA_ENV_"

// DefaultInfraReplicas is the default number of replicas for virt-api and virt-controller
DefaultInfraReplicas = 2
)

// DefaultMonitorNamespaces holds a set of well known prometheus-operator namespaces.
Expand Down
6 changes: 4 additions & 2 deletions tools/manifest-templator/manifest-templator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func main() {
virtLauncherSha := flag.String("virt-launcher-sha", "", "")
gsSha := flag.String("gs-sha", "", "")
featureGates := flag.String("feature-gates", "", "")
infraReplicas := flag.Uint("infra-replicas", 2, "")
infraReplicas := flag.Uint("infra-replicas", 0, "")

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true
Expand Down Expand Up @@ -148,7 +148,9 @@ func main() {
if *featureGates != "" {
data.FeatureGates = strings.Split(*featureGates, ",")
}
data.InfraReplicas = uint8(*infraReplicas)
if *infraReplicas != 0 {
data.InfraReplicas = uint8(*infraReplicas)
}

// operator deployment differs a bit in normal manifest and CSV
if strings.Contains(*inputFile, ".clusterserviceversion.yaml") {
Expand Down
6 changes: 5 additions & 1 deletion tools/resource-generator/resource-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ $1{{- end}}{{else}} []{{end}}`)
// However, when creating a template, we want its value to be something like "{{.InfraReplicas}}", which is not a uint8.
// Therefore, the value was substituted for a placeholder above (255). Replacing with the templated value now.
if strings.HasPrefix(*infraReplicasFlag, "{{") {
cr = strings.Replace(cr, fmt.Sprintf("replicas: %d", infraReplicasPlaceholder), "replicas: "+*infraReplicasFlag, 1)
infraReplicasVar := strings.TrimPrefix(*infraReplicasFlag, "{{")
infraReplicasVar = strings.TrimSuffix(infraReplicasVar, "}}")
re := regexp.MustCompile(`(?m)\n([ \t]+)replicas: ` + fmt.Sprintf("%d", infraReplicasPlaceholder))
cr = re.ReplaceAllString(cr, `{{if `+infraReplicasVar+`}}
${1}replicas: {{`+infraReplicasVar+`}}{{end}}`)
}

fmt.Print(cr)
Expand Down

0 comments on commit 7942f32

Please sign in to comment.