diff options
author | baude <bbaude@redhat.com> | 2020-12-14 11:33:25 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2020-12-17 09:40:51 -0600 |
commit | 86335aa4ae01dadecd36468409d742e68b76925d (patch) | |
tree | fd6e5bfeb924db9020073685d0133b2fa38622c1 /pkg/bindings/play | |
parent | c38ae47a1adf3235d8b01d724e7327e608dd8078 (diff) | |
download | podman-86335aa4ae01dadecd36468409d742e68b76925d.tar.gz podman-86335aa4ae01dadecd36468409d742e68b76925d.tar.bz2 podman-86335aa4ae01dadecd36468409d742e68b76925d.zip |
misc bindings to podman v3
manifest, system, info, volumes, play, and generate bindings are
updated to always have binding options.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/play')
-rw-r--r-- | pkg/bindings/play/play.go | 24 | ||||
-rw-r--r-- | pkg/bindings/play/types.go | 32 | ||||
-rw-r--r-- | pkg/bindings/play/types_kube_options.go | 280 |
3 files changed, 325 insertions, 11 deletions
diff --git a/pkg/bindings/play/play.go b/pkg/bindings/play/play.go index cfb40d74b..9ee02a093 100644 --- a/pkg/bindings/play/play.go +++ b/pkg/bindings/play/play.go @@ -3,18 +3,19 @@ package play import ( "context" "net/http" - "net/url" "os" "strconv" - "github.com/containers/image/v5/types" "github.com/containers/podman/v2/pkg/auth" "github.com/containers/podman/v2/pkg/bindings" "github.com/containers/podman/v2/pkg/domain/entities" ) -func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (*entities.PlayKubeReport, error) { +func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.PlayKubeReport, error) { var report entities.PlayKubeReport + if options == nil { + options = new(KubeOptions) + } conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -26,18 +27,19 @@ func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (* } defer f.Close() - params := url.Values{} - params.Set("network", options.Network) - params.Set("logDriver", options.LogDriver) - if options.SkipTLSVerify != types.OptionalBoolUndefined { - params.Set("tlsVerify", strconv.FormatBool(options.SkipTLSVerify != types.OptionalBoolTrue)) + params, err := options.ToParams() + if err != nil { + return nil, err + } + if options.SkipTLSVerify != nil { + params.Set("tlsVerify", strconv.FormatBool(options.GetSkipTLSVerify())) } - if options.Start != types.OptionalBoolUndefined { - params.Set("start", strconv.FormatBool(options.Start == types.OptionalBoolTrue)) + if options.Start != nil { + params.Set("start", strconv.FormatBool(options.GetStart())) } // TODO: have a global system context we can pass around (1st argument) - header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.Authfile, options.Username, options.Password) + header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.GetAuthfile(), options.GetUsername(), options.GetPassword()) if err != nil { return nil, err } diff --git a/pkg/bindings/play/types.go b/pkg/bindings/play/types.go new file mode 100644 index 000000000..5fb9a4d41 --- /dev/null +++ b/pkg/bindings/play/types.go @@ -0,0 +1,32 @@ +package play + +//go:generate go run ../generator/generator.go KubeOptions +// KubeOptions are optional options for replaying kube YAML files +type KubeOptions struct { + // Authfile - path to an authentication file. + Authfile *string + // CertDir - to a directory containing TLS certifications and keys. + CertDir *string + // Username for authenticating against the registry. + Username *string + // Password for authenticating against the registry. + Password *string + // Network - name of the CNI network to connect to. + Network *string + // Quiet - suppress output when pulling images. + Quiet *bool + // SignaturePolicy - path to a signature-policy file. + SignaturePolicy *string + // SkipTLSVerify - skip https and certificate validation when + // contacting container registries. + SkipTLSVerify *bool + // SeccompProfileRoot - path to a directory containing seccomp + // profiles. + SeccompProfileRoot *string + // ConfigMaps - slice of pathnames to kubernetes configmap YAMLs. + ConfigMaps *[]string + // LogDriver for the container. For example: journald + LogDriver *string + // Start - don't start the pod if false + Start *bool +} diff --git a/pkg/bindings/play/types_kube_options.go b/pkg/bindings/play/types_kube_options.go new file mode 100644 index 000000000..29a5fc9b1 --- /dev/null +++ b/pkg/bindings/play/types_kube_options.go @@ -0,0 +1,280 @@ +package play + +import ( + "net/url" + "reflect" + "strconv" + + jsoniter "github.com/json-iterator/go" + "github.com/pkg/errors" +) + +/* +This file is generated automatically by go generate. Do not edit. + +Created 2020-12-16 11:59:11.20490387 -0600 CST m=+0.000181859 +*/ + +// Changed +func (o *KubeOptions) Changed(fieldName string) bool { + r := reflect.ValueOf(o) + value := reflect.Indirect(r).FieldByName(fieldName) + return !value.IsNil() +} + +// ToParams +func (o *KubeOptions) 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 + } + 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() + slice := reflect.MakeSlice(reflect.SliceOf(typ), f.Len(), f.Cap()) + switch typ.Kind() { + case reflect.String: + s, ok := slice.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 +} + +// WithAuthfile +func (o *KubeOptions) WithAuthfile(value string) *KubeOptions { + v := &value + o.Authfile = v + return o +} + +// GetAuthfile +func (o *KubeOptions) GetAuthfile() string { + var authfile string + if o.Authfile == nil { + return authfile + } + return *o.Authfile +} + +// WithCertDir +func (o *KubeOptions) WithCertDir(value string) *KubeOptions { + v := &value + o.CertDir = v + return o +} + +// GetCertDir +func (o *KubeOptions) GetCertDir() string { + var certDir string + if o.CertDir == nil { + return certDir + } + return *o.CertDir +} + +// WithUsername +func (o *KubeOptions) WithUsername(value string) *KubeOptions { + v := &value + o.Username = v + return o +} + +// GetUsername +func (o *KubeOptions) GetUsername() string { + var username string + if o.Username == nil { + return username + } + return *o.Username +} + +// WithPassword +func (o *KubeOptions) WithPassword(value string) *KubeOptions { + v := &value + o.Password = v + return o +} + +// GetPassword +func (o *KubeOptions) GetPassword() string { + var password string + if o.Password == nil { + return password + } + return *o.Password +} + +// WithNetwork +func (o *KubeOptions) WithNetwork(value string) *KubeOptions { + v := &value + o.Network = v + return o +} + +// GetNetwork +func (o *KubeOptions) GetNetwork() string { + var network string + if o.Network == nil { + return network + } + return *o.Network +} + +// WithQuiet +func (o *KubeOptions) WithQuiet(value bool) *KubeOptions { + v := &value + o.Quiet = v + return o +} + +// GetQuiet +func (o *KubeOptions) GetQuiet() bool { + var quiet bool + if o.Quiet == nil { + return quiet + } + return *o.Quiet +} + +// WithSignaturePolicy +func (o *KubeOptions) WithSignaturePolicy(value string) *KubeOptions { + v := &value + o.SignaturePolicy = v + return o +} + +// GetSignaturePolicy +func (o *KubeOptions) GetSignaturePolicy() string { + var signaturePolicy string + if o.SignaturePolicy == nil { + return signaturePolicy + } + return *o.SignaturePolicy +} + +// WithSkipTLSVerify +func (o *KubeOptions) WithSkipTLSVerify(value bool) *KubeOptions { + v := &value + o.SkipTLSVerify = v + return o +} + +// GetSkipTLSVerify +func (o *KubeOptions) GetSkipTLSVerify() bool { + var skipTLSVerify bool + if o.SkipTLSVerify == nil { + return skipTLSVerify + } + return *o.SkipTLSVerify +} + +// WithSeccompProfileRoot +func (o *KubeOptions) WithSeccompProfileRoot(value string) *KubeOptions { + v := &value + o.SeccompProfileRoot = v + return o +} + +// GetSeccompProfileRoot +func (o *KubeOptions) GetSeccompProfileRoot() string { + var seccompProfileRoot string + if o.SeccompProfileRoot == nil { + return seccompProfileRoot + } + return *o.SeccompProfileRoot +} + +// WithConfigMaps +func (o *KubeOptions) WithConfigMaps(value []string) *KubeOptions { + v := &value + o.ConfigMaps = v + return o +} + +// GetConfigMaps +func (o *KubeOptions) GetConfigMaps() []string { + var configMaps []string + if o.ConfigMaps == nil { + return configMaps + } + return *o.ConfigMaps +} + +// WithLogDriver +func (o *KubeOptions) WithLogDriver(value string) *KubeOptions { + v := &value + o.LogDriver = v + return o +} + +// GetLogDriver +func (o *KubeOptions) GetLogDriver() string { + var logDriver string + if o.LogDriver == nil { + return logDriver + } + return *o.LogDriver +} + +// WithStart +func (o *KubeOptions) WithStart(value bool) *KubeOptions { + v := &value + o.Start = v + return o +} + +// GetStart +func (o *KubeOptions) GetStart() bool { + var start bool + if o.Start == nil { + return start + } + return *o.Start +} |