summaryrefslogtreecommitdiff
path: root/pkg/bindings/pods
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-01-19 08:47:37 -0500
committerGitHub <noreply@github.com>2021-01-19 08:47:37 -0500
commit8c6df5e93e6941a7f50da651678751f7dfec900e (patch)
tree11c249515e428afe98e353b497d2d6abd1ae7ca3 /pkg/bindings/pods
parent9a10f20bc1a8733f2a4025d4a1bca45aa31db0d7 (diff)
parent4ccb0729b4f0a25eb53f62c2f6ca7f8925f0fe4e (diff)
downloadpodman-8c6df5e93e6941a7f50da651678751f7dfec900e.tar.gz
podman-8c6df5e93e6941a7f50da651678751f7dfec900e.tar.bz2
podman-8c6df5e93e6941a7f50da651678751f7dfec900e.zip
Merge pull request #9004 from baude/existsoptions
Add binding options for container|pod exists
Diffstat (limited to 'pkg/bindings/pods')
-rw-r--r--pkg/bindings/pods/pods.go2
-rw-r--r--pkg/bindings/pods/types.go5
-rw-r--r--pkg/bindings/pods/types_exists_options.go88
3 files changed, 94 insertions, 1 deletions
diff --git a/pkg/bindings/pods/pods.go b/pkg/bindings/pods/pods.go
index 4fcaf81f1..ef30348f8 100644
--- a/pkg/bindings/pods/pods.go
+++ b/pkg/bindings/pods/pods.go
@@ -38,7 +38,7 @@ func CreatePodFromSpec(ctx context.Context, s *specgen.PodSpecGenerator, options
}
// Exists is a lightweight method to determine if a pod exists in local storage
-func Exists(ctx context.Context, nameOrID string) (bool, error) {
+func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool, error) {
conn, err := bindings.GetClient(ctx)
if err != nil {
return false, err
diff --git a/pkg/bindings/pods/types.go b/pkg/bindings/pods/types.go
index 370c1aaa9..cb41cf623 100644
--- a/pkg/bindings/pods/types.go
+++ b/pkg/bindings/pods/types.go
@@ -70,3 +70,8 @@ type StatsOptions struct {
type RemoveOptions struct {
Force *bool
}
+
+//go:generate go run ../generator/generator.go ExistsOptions
+// ExistsOptions are optional options for checking if a pod exists
+type ExistsOptions struct {
+}
diff --git a/pkg/bindings/pods/types_exists_options.go b/pkg/bindings/pods/types_exists_options.go
new file mode 100644
index 000000000..7221afe74
--- /dev/null
+++ b/pkg/bindings/pods/types_exists_options.go
@@ -0,0 +1,88 @@
+package pods
+
+import (
+ "net/url"
+ "reflect"
+ "strconv"
+ "strings"
+
+ jsoniter "github.com/json-iterator/go"
+ "github.com/pkg/errors"
+)
+
+/*
+This file is generated automatically by go generate. Do not edit.
+*/
+
+// Changed
+func (o *ExistsOptions) Changed(fieldName string) bool {
+ r := reflect.ValueOf(o)
+ value := reflect.Indirect(r).FieldByName(fieldName)
+ return !value.IsNil()
+}
+
+// ToParams
+func (o *ExistsOptions) ToParams() (url.Values, error) {
+ params := url.Values{}
+ if o == nil {
+ return params, nil
+ }
+ json := jsoniter.ConfigCompatibleWithStandardLibrary
+ s := reflect.ValueOf(o)
+ if reflect.Ptr == s.Kind() {
+ s = s.Elem()
+ }
+ sType := s.Type()
+ for i := 0; i < s.NumField(); i++ {
+ fieldName := sType.Field(i).Name
+ if !o.Changed(fieldName) {
+ continue
+ }
+ fieldName = strings.ToLower(fieldName)
+ f := s.Field(i)
+ if reflect.Ptr == f.Kind() {
+ f = f.Elem()
+ }
+ switch f.Kind() {
+ case reflect.Bool:
+ params.Set(fieldName, strconv.FormatBool(f.Bool()))
+ case reflect.String:
+ params.Set(fieldName, f.String())
+ case reflect.Int, reflect.Int64:
+ // f.Int() is always an int64
+ params.Set(fieldName, strconv.FormatInt(f.Int(), 10))
+ case reflect.Uint, reflect.Uint64:
+ // f.Uint() is always an uint64
+ params.Set(fieldName, strconv.FormatUint(f.Uint(), 10))
+ case reflect.Slice:
+ typ := reflect.TypeOf(f.Interface()).Elem()
+ switch typ.Kind() {
+ case reflect.String:
+ sl := f.Slice(0, f.Len())
+ s, ok := sl.Interface().([]string)
+ if !ok {
+ return nil, errors.New("failed to convert to string slice")
+ }
+ for _, val := range s {
+ params.Add(fieldName, val)
+ }
+ default:
+ return nil, errors.Errorf("unknown slice type %s", f.Kind().String())
+ }
+ case reflect.Map:
+ lowerCaseKeys := make(map[string][]string)
+ iter := f.MapRange()
+ for iter.Next() {
+ lowerCaseKeys[iter.Key().Interface().(string)] = iter.Value().Interface().([]string)
+
+ }
+ s, err := json.MarshalToString(lowerCaseKeys)
+ if err != nil {
+ return nil, err
+ }
+
+ params.Set(fieldName, s)
+ }
+ }
+ return params, nil
+}