mirror of
https://github.com/containers/podman.git
synced 2025-10-25 10:16:43 +08:00
kube play: update the handling of PersistentVolumeClaim
Up - do not fail if volume already exists, use the existing one Down - allow the user to remove the volume by passing --force Add tests Update the documentation Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
@ -60,6 +60,8 @@ type PlayKubeOptions struct {
|
||||
Userns string
|
||||
// IsRemote - was the request triggered by running podman-remote
|
||||
IsRemote bool
|
||||
// Force - remove volumes on --down
|
||||
Force bool
|
||||
}
|
||||
|
||||
// PlayKubePod represents a single pod and associated containers created by play kube
|
||||
@ -96,12 +98,16 @@ type PlayKubeReport struct {
|
||||
type KubePlayReport = PlayKubeReport
|
||||
|
||||
// PlayKubeDownOptions are options for tearing down pods
|
||||
type PlayKubeDownOptions struct{}
|
||||
type PlayKubeDownOptions struct {
|
||||
// Force - remove volumes if passed
|
||||
Force bool
|
||||
}
|
||||
|
||||
// PlayKubeDownReport contains the results of tearing down play kube
|
||||
type PlayKubeTeardown struct {
|
||||
StopReport []*PodStopReport
|
||||
RmReport []*PodRmReport
|
||||
StopReport []*PodStopReport
|
||||
RmReport []*PodRmReport
|
||||
VolumeRmReport []*VolumeRmReport
|
||||
}
|
||||
|
||||
type PlaySecret struct {
|
||||
|
||||
@ -869,6 +869,7 @@ func (ic *ContainerEngine) playKubePVC(ctx context.Context, pvcYAML *v1.Persiste
|
||||
volOptions := []libpod.VolumeCreateOption{
|
||||
libpod.WithVolumeName(name),
|
||||
libpod.WithVolumeLabels(pvcYAML.Labels),
|
||||
libpod.WithVolumeIgnoreIfExist(),
|
||||
}
|
||||
|
||||
// Get pvc annotations and create remaining podman volume options if available.
|
||||
@ -1110,9 +1111,10 @@ func getBuildFile(imageName string, cwd string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, _ entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) {
|
||||
func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, options entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) {
|
||||
var (
|
||||
podNames []string
|
||||
podNames []string
|
||||
volumeNames []string
|
||||
)
|
||||
reports := new(entities.PlayKubeReport)
|
||||
|
||||
@ -1162,6 +1164,12 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, _ e
|
||||
podName := fmt.Sprintf("%s-pod-%d", deploymentName, i)
|
||||
podNames = append(podNames, podName)
|
||||
}
|
||||
case "PersistentVolumeClaim":
|
||||
var pvcYAML v1.PersistentVolumeClaim
|
||||
if err := yaml.Unmarshal(document, &pvcYAML); err != nil {
|
||||
return nil, fmt.Errorf("unable to read YAML as Kube PersistentVolumeClaim: %w", err)
|
||||
}
|
||||
volumeNames = append(volumeNames, pvcYAML.Name)
|
||||
default:
|
||||
continue
|
||||
}
|
||||
@ -1178,6 +1186,13 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, _ e
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options.Force {
|
||||
reports.VolumeRmReport, err = ic.VolumeRm(ctx, volumeNames, entities.VolumeRmOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return reports, nil
|
||||
}
|
||||
|
||||
|
||||
@ -75,8 +75,8 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, opts en
|
||||
return play.KubeWithBody(ic.ClientCtx, body, options)
|
||||
}
|
||||
|
||||
func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, _ entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) {
|
||||
return play.DownWithBody(ic.ClientCtx, body)
|
||||
func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, options entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) {
|
||||
return play.DownWithBody(ic.ClientCtx, body, kube.DownOptions{Force: &options.Force})
|
||||
}
|
||||
|
||||
func (ic *ContainerEngine) KubeApply(ctx context.Context, body io.Reader, opts entities.ApplyOptions) error {
|
||||
|
||||
Reference in New Issue
Block a user