Skip to content

Commit

Permalink
update hook.yaml during init
Browse files Browse the repository at this point in the history
Signed-off-by: mintcckey <[email protected]>
  • Loading branch information
mintcckey committed Oct 13, 2023
1 parent f4c56c8 commit 068967c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ require (
sigs.k8s.io/controller-runtime v0.9.6
sigs.k8s.io/yaml v1.2.0
)

replace github.com/milvus-io/milvus-operator => github.com/mintcckey/milvus-operator-new v0.8.3-r2
8 changes: 8 additions & 0 deletions pkg/controllers/deployment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type deploymentUpdater interface {
GetPersistenceConfig() *v1beta1.Persistence
GetMilvus() *v1beta1.Milvus
RollingUpdateImageDependencyReady() bool
HasHookConfig() bool
}

func updateDeployment(deployment *appsv1.Deployment, updater deploymentUpdater) error {
Expand Down Expand Up @@ -192,6 +193,9 @@ func updateMilvusContainer(template *corev1.PodTemplateSpec, updater deploymentU

addVolumeMount(&container.VolumeMounts, configVolumeMount)
addVolumeMount(&container.VolumeMounts, toolVolumeMount)
if updater.HasHookConfig() {
addVolumeMount(&container.VolumeMounts, hookConfigVolumeMount)
}

Check warning on line 198 in pkg/controllers/deployment_updater.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/deployment_updater.go#L197-L198

Added lines #L197 - L198 were not covered by tests
if persistence := updater.GetPersistenceConfig(); persistence != nil && persistence.Enabled {
addVolumeMount(&container.VolumeMounts, persistentVolumeMount(*persistence))
}
Expand Down Expand Up @@ -347,3 +351,7 @@ func (m milvusDeploymentUpdater) RollingUpdateImageDependencyReady() bool {
}
return true
}

func (m milvusDeploymentUpdater) HasHookConfig() bool {
return len(m.Milvus.Spec.HookConf.Data) > 0
}
26 changes: 17 additions & 9 deletions pkg/controllers/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ import (
)

const (
MilvusDataVolumeName = "milvus-data" // for standalone persistence only
MilvusConfigVolumeName = "milvus-config"
MilvusOriginalConfigPath = "/milvus/configs/milvus.yaml"
MilvusUserConfigMountPath = "/milvus/configs/user.yaml"
MilvusUserConfigMountSubPath = "user.yaml"
MilvusHookConfigMountSubPath = "hook.yaml"
AccessKey = "accesskey"
SecretKey = "secretkey"
AnnotationCheckSum = "checksum/config"
MilvusDataVolumeName = "milvus-data" // for standalone persistence only
MilvusConfigVolumeName = "milvus-config"
MilvusOriginalConfigPath = "/milvus/configs/milvus.yaml"
MilvusUserConfigMountPath = "/milvus/configs/user.yaml"
MilvusHookConfigUpdatesMountPath = "/milvus/configs/hook_updates.yaml"
MilvusUserConfigMountSubPath = "user.yaml"
MilvusHookConfigMountSubPath = "hook.yaml"
AccessKey = "accesskey"
SecretKey = "secretkey"
AnnotationCheckSum = "checksum/config"

ToolsVolumeName = "tools"
ToolsMountPath = "/milvus/tools"
Expand Down Expand Up @@ -267,6 +268,13 @@ var (
MountPath: MilvusUserConfigMountPath,
SubPath: MilvusUserConfigMountSubPath,
}

hookConfigVolumeMount = corev1.VolumeMount{
Name: MilvusConfigVolumeName,
ReadOnly: true,
MountPath: MilvusHookConfigUpdatesMountPath,
SubPath: MilvusHookConfigMountSubPath,
}
)

func configVolumeByName(name string) corev1.Volume {
Expand Down
3 changes: 3 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
set -e
MilvusUserConfigMountPath="/milvus/configs/user.yaml"
MilvusOriginalConfigPath="/milvus/configs/milvus.yaml"
MilvusHookConfigMountPath="/milvus/configs/hook.yaml"
MilvusHookConfigUpdatesMountPath="/milvus/configs/hook_updates.yaml"
# merge config
/milvus/tools/merge -s ${MilvusUserConfigMountPath} -d ${MilvusOriginalConfigPath}
/milvus/tools/merge -s ${MilvusHookConfigUpdatesMountPath} -d ${MilvusHookConfigMountPath}
# run commands
exec $@
14 changes: 14 additions & 0 deletions tool/merge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var mqConfigsToDelete = map[string]bool{
"pulsar": true,
}

func checkFileExists(filepath string) bool {
_, err := os.Stat(filepath)
return err == nil
}

func main() {
srcPath := flag.String("s", "", "source yaml path, will overwrite the dst config")
dstPath := flag.String("d", "", "destination yaml path, will be overwritten by the src config")
Expand All @@ -28,6 +33,15 @@ func main() {
return
}

if !checkFileExists(*srcPath) {
log.Println("missing source yaml")
os.Exit(0)
}
if !checkFileExists(*dstPath) {
log.Println("missing destination yaml")
os.Exit(0)
}

src, err := readYaml(*srcPath)
if err != nil {
log.Fatal("read source yaml failed: ", err)
Expand Down

0 comments on commit 068967c

Please sign in to comment.