Skip to content

Commit

Permalink
Add initial hound-search controller
Browse files Browse the repository at this point in the history
This change setups the initial hound service.
A follow-up is required to generate the repo list from the zuul tenant config.

RHOSZUUL-2163

Change-Id: I0e1151c8fa29e44f5f8d263797f4566345a00336
  • Loading branch information
TristanCacqueray committed Feb 10, 2025
1 parent 8b1b41c commit d07f081
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 14 deletions.
4 changes: 2 additions & 2 deletions controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ func (r *SFController) SetupBaseSecrets(internalTenantSecretsVersion string) boo
}

roleAnnotations := map[string]string{
"serial": "2",
"serial": "3",
}

roleName := "config-updater-role"
roleRules := []rbacv1.PolicyRule{
{
APIGroups: []string{""},
Resources: []string{"pods"},
Verbs: []string{"get", "list"},
Verbs: []string{"get", "list", "delete"},
},
{
APIGroups: []string{""},
Expand Down
64 changes: 64 additions & 0 deletions controllers/hound-search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (C) 2024 Red Hat
// SPDX-License-Identifier: Apache-2.0

package controllers

import (
v1 "github.com/softwarefactory-project/sf-operator/api/v1"
"github.com/softwarefactory-project/sf-operator/controllers/libs/base"
"github.com/softwarefactory-project/sf-operator/controllers/libs/utils"
apiv1 "k8s.io/api/core/v1"
)

func MkHoundSearchContainer() apiv1.Container {
container := base.MkContainer("hound-search", "quay.io/software-factory/hound:0.5.1-1")
container.Command = []string{"/sf-tooling/hound-search-init.sh"}
container.Ports = []apiv1.ContainerPort{
base.MkContainerPort(6080, "hound-search"),
}
container.ReadinessProbe = base.MkReadinessHTTPProbe("/", 6080)
container.VolumeMounts = []apiv1.VolumeMount{
{
Name: "hound-search-data",
MountPath: "/var/lib/hound",
},
{
Name: "zuul-config",
MountPath: "/etc/zuul",
ReadOnly: true,
},
{
Name: "tooling-vol",
MountPath: "/sf-tooling",
ReadOnly: true,
},
}
return container
}

func (r *SFController) DeployHoundSearch() bool {
svc := base.MkService("hound-search", r.ns, "hound-search", []int32{6080}, "hound-search", r.cr.Spec.ExtraLabels)
r.EnsureService(&svc)
pvc := base.MkPVC("hound-search-data", r.ns, BaseGetStorageConfOrDefault(v1.StorageSpec{}, r.cr.Spec.StorageDefault), apiv1.ReadWriteOnce)
container := MkHoundSearchContainer()
container.Env = []apiv1.EnvVar{
base.MkEnvVar("CONFIG_REPO_BASE_URL", r.cr.Spec.ConfigRepositoryLocation.BaseURL),
base.MkEnvVar("CONFIG_REPO_NAME", r.cr.Spec.ConfigRepositoryLocation.Name),
}
sts := base.MkStatefulset("hound-search", r.ns, 1, "hound-search", container, pvc, r.cr.Spec.ExtraLabels)
sts.Spec.Template.Spec.Volumes = AppendToolingVolume(sts.Spec.Template.Spec.Volumes)
sts.Spec.Template.Spec.Volumes = append(sts.Spec.Template.Spec.Volumes, base.MkVolumeSecret("zuul-config"))

annotations := map[string]string{
"config-repo-info": r.cr.Spec.ConfigRepositoryLocation.BaseURL + r.cr.Spec.ConfigRepositoryLocation.Name,
}
sts.Spec.Template.ObjectMeta.Annotations = annotations
current, stsUpdated := r.ensureStatefulset(sts)
if !utils.MapEquals(&current.Spec.Template.ObjectMeta.Annotations, &annotations) {
utils.LogI("hound configuration changed, rollout pods ...")
current.Spec = sts.DeepCopy().Spec
r.UpdateR(current)
return false
}
return !stsUpdated
}
1 change: 1 addition & 0 deletions controllers/softwarefactory_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func (r *SFController) deploySFStep(services map[string]bool) map[string]bool {
}

if services["Zuul"] {
services["HoundSearch"] = r.DeployHoundSearch()
monitoredPorts = append(
monitoredPorts,
sfmonitoring.GetTruncatedPortName("zuul-scheduler", sfmonitoring.NodeExporterPortNameSuffix),
Expand Down
3 changes: 3 additions & 0 deletions controllers/static/gateway/gateway.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
# Handle LogJuicer requests
ProxyPassMatch "^/logjuicer/wsapi/(.*)$" "ws://logjuicer:3000/wsapi/$1" retry=0
ProxyPass "/logjuicer" "http://logjuicer:3000" retry=0

# Handle hound search requets
ProxyPass "/codesearch" "http://hound-search:6080" retry=0
</IfModule>
7 changes: 7 additions & 0 deletions controllers/static/git-server/update-system-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ cat << EOF > playbooks/config/update.yaml
roles:
- setup-k8s-config
- add-k8s-hosts
post_tasks:
- name: Update hound-search config
command: kubectl exec hound-search-0 -- /sf-tooling/hound-search-config.sh "{{ zuul.newrev | default('origin/master') }}"
# Would be nice to hot-reload the config: https://github.com/hound-search/hound/issues/287
# Or check if the repo list is changed (to avoid restarting hound each time a change is merged)
- name: Force hound-search restart
command: kubectl delete pod hound-search-0
- hosts: zuul-scheduler
vars:
Expand Down
10 changes: 10 additions & 0 deletions controllers/static/hound-search-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# Copyright (C) 2025 Red Hat
# SPDX-License-Identifier: Apache-2.0

set -ex

export HOME=/var/lib/hound
bash /sf-tooling/fetch-config-repo.sh $1

# TODO: Render the config
22 changes: 22 additions & 0 deletions controllers/static/hound-search-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Copyright (C) 2025 Red Hat
# SPDX-License-Identifier: Apache-2.0

set -ex

export HOME=/var/lib/hound
mkdir -p ${HOME}/data
cd $HOME
if [ ! -z "${CONFIG_REPO_BASE_URL}" ]; then
bash /sf-tooling/hound-search-config.sh
fi
if [ ! -f "/var/lib/hound/config.json" ]; then
cat <<EOF> /var/lib/hound/config.json
{
"dbpath": "/var/lib/hound/data",
"max-concurrent-indexers": 2,
"repos": {}
}
EOF
fi
exec /go/bin/houndd -conf /var/lib/hound/config.json
13 changes: 13 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,16 @@ func AppendCorporateCACertsVolumeMount(volumeMounts []apiv1.VolumeMount, volumeN
})
return volumeMounts
}

func AppendToolingVolume(volumeMounts []apiv1.Volume) []apiv1.Volume {
return append(volumeMounts, apiv1.Volume{
Name: "tooling-vol",
VolumeSource: apiv1.VolumeSource{
ConfigMap: &apiv1.ConfigMapVolumeSource{
LocalObjectReference: apiv1.LocalObjectReference{
Name: "zuul-scheduler-tooling-config-map",
},
DefaultMode: &utils.Execmod,
},
}})
}
21 changes: 9 additions & 12 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ var (
//go:embed static/zuul/zuul-change-dump.py.tmpl
zuulChangeDump string

//go:embed static/hound-search-init.sh
houndSearchInit string

//go:embed static/hound-search-config.sh
houndSearchConfig string

// Common config sections for all Zuul components
commonIniConfigSections = []string{"zookeeper", "keystore", "database"}

Expand Down Expand Up @@ -320,18 +326,7 @@ func mkZuulVolumes(service string, r *SFController, corporateCMExists bool) []ap
volumes = append(volumes, base.MkEmptyDirVolume(service))
}
if service == "zuul-scheduler" {
toolingVol := apiv1.Volume{
Name: "tooling-vol",
VolumeSource: apiv1.VolumeSource{
ConfigMap: &apiv1.ConfigMapVolumeSource{
LocalObjectReference: apiv1.LocalObjectReference{
Name: "zuul-scheduler-tooling-config-map",
},
DefaultMode: &utils.Execmod,
},
},
}
volumes = append(volumes, toolingVol)
volumes = AppendToolingVolume(volumes)
}

volumes = append(volumes, mkZuulConnectionSecretsVolumes(r)...)
Expand Down Expand Up @@ -530,6 +525,8 @@ func (r *SFController) EnsureZuulScheduler(cfg *ini.File) bool {
schedulerToolingData["init-container.sh"] = zuulSchedulerInitContainerScript
schedulerToolingData["generate-zuul-tenant-yaml.sh"] = zuulGenerateTenantConfig
schedulerToolingData["fetch-config-repo.sh"] = fetchConfigRepoScript
schedulerToolingData["hound-search-init.sh"] = houndSearchInit
schedulerToolingData["hound-search-config.sh"] = houndSearchConfig
schedulerToolingData["zuul-change-dump.py"], _ = utils.ParseString(zuulChangeDump, struct {
ZuulWebURL string
}{ZuulWebURL: "https://" + r.cr.Spec.FQDN + "/zuul"})
Expand Down

0 comments on commit d07f081

Please sign in to comment.