Skip to content

Commit

Permalink
Fix the bug when input the volume, volumeMount and securityContext as…
Browse files Browse the repository at this point in the history
… nul string.

Signed-off-by: Ye Cao <[email protected]>
  • Loading branch information
dashanji committed Dec 19, 2023
1 parent 3e2d27f commit 28a0e4a
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 24 deletions.
30 changes: 18 additions & 12 deletions k8s/cmd/commands/deploy/deploy_vineyardd.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,27 @@ func BuildVineyard() (*v1alpha1.Vineyardd, error) {
log.Fatal(err, "failed to build the vineyardd from input")
}
// parse the volume and volume mounts
volumes, err := util.ParseVolume(flags.VineyardVolume)
if err != nil {
log.Fatal(err, "failed to parse the volumes")
if flags.VineyardVolume != "" {
volumes, err := util.ParseVolume(flags.VineyardVolume)
if err != nil {
log.Fatal(err, "failed to parse the volumes")
}
vineyardd.Spec.Volumes = *volumes
}
volumeMounts, err := util.ParseVolumeMount(flags.VineyardVolumeMount)
if err != nil {
log.Fatal(err, "failed to parse the volume mounts")
if flags.VineyardVolumeMount != "" {
volumeMounts, err := util.ParseVolumeMount(flags.VineyardVolumeMount)
if err != nil {
log.Fatal(err, "failed to parse the volume mounts")
}
vineyardd.Spec.VolumeMounts = *volumeMounts
}
securityContext, err := util.ParseSecurityContext(flags.VineyardSecurityContext)
if err != nil {
log.Fatal(err, "failed to parse the security context")
if flags.VineyardSecurityContext != "" {
securityContext, err := util.ParseSecurityContext(flags.VineyardSecurityContext)
if err != nil {
log.Fatal(err, "failed to parse the security context")
}
vineyardd.Spec.SecurityContext = *securityContext
}
vineyardd.Spec.Volumes = *volumes
vineyardd.Spec.VolumeMounts = *volumeMounts
vineyardd.Spec.SecurityContext = *securityContext
return vineyardd, nil
}

Expand Down
30 changes: 18 additions & 12 deletions k8s/cmd/commands/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,21 +692,27 @@ func buildSidecar(namespace string) (*v1alpha1.Sidecar, error) {
},
Spec: *opts,
}
securityContext, err := util.ParseSecurityContext(flags.VineyardSecurityContext)
if err != nil {
return nil, errors.Wrap(err, "failed to parse security context of vineyard sidecar container")
if flags.VineyardSecurityContext != "" {
securityContext, err := util.ParseSecurityContext(flags.VineyardSecurityContext)
if err != nil {
return nil, errors.Wrap(err, "failed to parse security context of vineyard sidecar container")
}
sidecar.Spec.SecurityContext = *securityContext
}
volumes, err := util.ParseVolume(flags.VineyardVolume)
if err != nil {
return nil, errors.Wrap(err, "failed to parse volumes of vineyard sidecar container")
if flags.VineyardVolume != "" {
volumes, err := util.ParseVolume(flags.VineyardVolume)
if err != nil {
return nil, errors.Wrap(err, "failed to parse volumes of vineyard sidecar container")
}
sidecar.Spec.Volumes = *volumes
}
volumeMounts, err := util.ParseVolumeMount(flags.VineyardVolumeMount)
if err != nil {
return nil, errors.Wrap(err, "failed to parse volume mounts of vineyard sidecar container")
if flags.VineyardVolumeMount != "" {
volumeMounts, err := util.ParseVolumeMount(flags.VineyardVolumeMount)
if err != nil {
return nil, errors.Wrap(err, "failed to parse volume mounts of vineyard sidecar container")
}
sidecar.Spec.VolumeMounts = *volumeMounts
}
sidecar.Spec.SecurityContext = *securityContext
sidecar.Spec.Volumes = *volumes
sidecar.Spec.VolumeMounts = *volumeMounts
return sidecar, nil
}

Expand Down
Loading

0 comments on commit 28a0e4a

Please sign in to comment.