Secret create - add ignore option to allow noop

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
Ygal Blum
2025-06-18 16:28:48 -04:00
parent 1f1618fcb0
commit bfc327a08e
16 changed files with 138 additions and 36 deletions

View File

@ -27,6 +27,7 @@ func CreateSecret(w http.ResponseWriter, r *http.Request) {
DriverOpts map[string]string `schema:"driveropts"`
Labels map[string]string `schema:"labels"`
Replace bool `schema:"replace"`
Ignore bool `schema:"ignore"`
}{
// override any golang type defaults
}
@ -40,6 +41,7 @@ func CreateSecret(w http.ResponseWriter, r *http.Request) {
opts.DriverOpts = query.DriverOpts
opts.Labels = query.Labels
opts.Replace = query.Replace
opts.Ignore = query.Ignore
ic := abi.ContainerEngine{Libpod: runtime}
report, err := ic.SecretCreate(r.Context(), query.Name, r.Body, opts)

View File

@ -29,4 +29,5 @@ type CreateOptions struct {
DriverOpts map[string]string
Labels map[string]string
Replace *bool
Ignore *bool
}

View File

@ -91,3 +91,18 @@ func (o *CreateOptions) GetReplace() bool {
}
return *o.Replace
}
// WithIgnore set field Ignore to given value
func (o *CreateOptions) WithIgnore(value bool) *CreateOptions {
o.Ignore = &value
return o
}
// GetIgnore returns value of field Ignore
func (o *CreateOptions) GetIgnore() bool {
if o.Ignore == nil {
var z bool
return z
}
return *o.Ignore
}

View File

@ -12,6 +12,7 @@ type SecretCreateOptions struct {
DriverOpts map[string]string
Labels map[string]string
Replace bool
Ignore bool
}
type SecretInspectOptions struct {

View File

@ -47,9 +47,10 @@ func (ic *ContainerEngine) SecretCreate(ctx context.Context, name string, reader
}
storeOpts := secrets.StoreOptions{
DriverOpts: options.DriverOpts,
Labels: options.Labels,
Replace: options.Replace,
DriverOpts: options.DriverOpts,
Labels: options.Labels,
Replace: options.Replace,
IgnoreIfExists: options.Ignore,
}
secretID, err := manager.Store(name, data, options.Driver, storeOpts)

View File

@ -16,7 +16,8 @@ func (ic *ContainerEngine) SecretCreate(ctx context.Context, name string, reader
WithDriverOpts(options.DriverOpts).
WithName(name).
WithLabels(options.Labels).
WithReplace(options.Replace)
WithReplace(options.Replace).
WithIgnore(options.Ignore)
created, err := secrets.Create(ic.ClientCtx, reader, opts)
if err != nil {
return nil, err