Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -1342,12 +1342,83 @@ _oc_set_volumes()
must_have_one_noun=()
}

_oc_set_probe()
{
last_command="oc_set_probe"
commands=()

flags=()
two_word_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--all")
flags+=("--containers=")
two_word_flags+=("-c")
flags+=("--failure-threshold=")
flags+=("--filename=")
flags_with_completion+=("--filename")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
two_word_flags+=("-f")
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
flags+=("--get-url=")
flags+=("--initial-delay-seconds=")
flags+=("--liveness")
flags+=("--no-headers")
flags+=("--open-tcp=")
flags+=("--output=")
two_word_flags+=("-o")
flags+=("--output-version=")
flags+=("--period-seconds=")
flags+=("--readiness")
flags+=("--remove")
flags+=("--selector=")
two_word_flags+=("-l")
flags+=("--show-all")
flags+=("-a")
flags+=("--show-labels")
flags+=("--sort-by=")
flags+=("--success-threshold=")
flags+=("--template=")
two_word_flags+=("-t")
flags+=("--timeout-seconds=")
flags+=("--api-version=")
flags+=("--certificate-authority=")
flags_with_completion+=("--certificate-authority")
flags_completion+=("_filedir")
flags+=("--client-certificate=")
flags_with_completion+=("--client-certificate")
flags_completion+=("_filedir")
flags+=("--client-key=")
flags_with_completion+=("--client-key")
flags_completion+=("_filedir")
flags+=("--cluster=")
flags+=("--config=")
flags_with_completion+=("--config")
flags_completion+=("_filedir")
flags+=("--context=")
flags+=("--google-json-key=")
flags+=("--insecure-skip-tls-verify")
flags+=("--log-flush-frequency=")
flags+=("--match-server-version")
flags+=("--namespace=")
two_word_flags+=("-n")
flags+=("--server=")
flags+=("--token=")
flags+=("--user=")

must_have_one_flag=()
must_have_one_noun=()
}

_oc_set()
{
last_command="oc_set"
commands=()
commands+=("env")
commands+=("volumes")
commands+=("probe")

flags=()
two_word_flags=()
Expand Down
71 changes: 71 additions & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -4679,12 +4679,83 @@ _openshift_cli_set_volumes()
must_have_one_noun=()
}

_openshift_cli_set_probe()
{
last_command="openshift_cli_set_probe"
commands=()

flags=()
two_word_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--all")
flags+=("--containers=")
two_word_flags+=("-c")
flags+=("--failure-threshold=")
flags+=("--filename=")
flags_with_completion+=("--filename")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
two_word_flags+=("-f")
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
flags+=("--get-url=")
flags+=("--initial-delay-seconds=")
flags+=("--liveness")
flags+=("--no-headers")
flags+=("--open-tcp=")
flags+=("--output=")
two_word_flags+=("-o")
flags+=("--output-version=")
flags+=("--period-seconds=")
flags+=("--readiness")
flags+=("--remove")
flags+=("--selector=")
two_word_flags+=("-l")
flags+=("--show-all")
flags+=("-a")
flags+=("--show-labels")
flags+=("--sort-by=")
flags+=("--success-threshold=")
flags+=("--template=")
two_word_flags+=("-t")
flags+=("--timeout-seconds=")
flags+=("--api-version=")
flags+=("--certificate-authority=")
flags_with_completion+=("--certificate-authority")
flags_completion+=("_filedir")
flags+=("--client-certificate=")
flags_with_completion+=("--client-certificate")
flags_completion+=("_filedir")
flags+=("--client-key=")
flags_with_completion+=("--client-key")
flags_completion+=("_filedir")
flags+=("--cluster=")
flags+=("--config=")
flags_with_completion+=("--config")
flags_completion+=("_filedir")
flags+=("--context=")
flags+=("--google-json-key=")
flags+=("--insecure-skip-tls-verify")
flags+=("--log-flush-frequency=")
flags+=("--match-server-version")
flags+=("--namespace=")
two_word_flags+=("-n")
flags+=("--server=")
flags+=("--token=")
flags+=("--user=")

must_have_one_flag=()
must_have_one_noun=()
}

_openshift_cli_set()
{
last_command="openshift_cli_set"
commands=()
commands+=("env")
commands+=("volumes")
commands+=("probe")

flags=()
two_word_flags=()
Expand Down
28 changes: 28 additions & 0 deletions docs/generated/oc_by_example_content.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,34 @@ Update environment variables on a pod template
====


== oc set probe
Update a probe on a pod template

====

[options="nowrap"]
----
# Clear both readiness and liveness probes off all containers
$ oc set probe dc/registry --remove --readiness --liveness

# Set an exec action as a liveness probe to run 'echo ok'
$ oc set probe dc/registry --liveness -- echo ok

# Set a readiness probe to try to open a TCP socket on 3306
$ oc set probe rc/mysql --readiness --open-tcp=3306

# Set an HTTP readiness probe for port 8080 and path /healthz over HTTP on the pod IP
$ oc set probe dc/webapp --readiness --get-url=http://:8080/healthz

# Set an HTTP readiness probe over HTTPS on 127.0.0.1 for a hostNetwork pod
$ oc set probe dc/router --readiness --get-url=https://127.0.0.1:1936/stats

# Set only the initial-delay-seconds field on all deployments
$ oc set probe dc --all --readiness --initial-delay-seconds=30
----
====


== oc set volumes
Update volumes on a pod template

Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/cli/cmd/set/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func validateNoOverwrites(meta *kapi.ObjectMeta, labels map[string]string) error
}

// RunEnv contains all the necessary functionality for the OpenShift cli env command
// TODO: refactor to share the common "patch resource" pattern of probe
func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Command, args []string, envParams, filenames []string) error {
resources, envArgs := []string{}, []string{}
first := true
Expand Down
51 changes: 51 additions & 0 deletions pkg/cmd/cli/cmd/set/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (

kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/strategicpatch"
)

func selectContainers(containers []kapi.Container, spec string) ([]*kapi.Container, []*kapi.Container) {
Expand Down Expand Up @@ -115,3 +118,51 @@ func findEnv(env []kapi.EnvVar, name string) (kapi.EnvVar, bool) {
}
return kapi.EnvVar{}, false
}

// Patch represents the result of a mutation to an object.
type Patch struct {
Info *resource.Info
Err error

Before []byte
After []byte
Patch []byte
}

// CalculatePatches calls the mutation function on each provided info object, and generates a strategic merge patch for
// the changes in the object. Encoder must be able to encode the info into the appropriate destination type. If mutateFn
// returns false, the object is not included in the final list of patches.
func CalculatePatches(infos []*resource.Info, encoder runtime.Encoder, mutateFn func(*resource.Info) (bool, error)) []*Patch {
var patches []*Patch
for _, info := range infos {
patch := &Patch{Info: info}
patch.Before, patch.Err = runtime.Encode(encoder, info.Object)

ok, err := mutateFn(info)
if !ok {
continue
}
if err != nil {
patch.Err = err
}
patches = append(patches, patch)
if patch.Err != nil {
continue
}

patch.After, patch.Err = runtime.Encode(encoder, info.Object)
if patch.Err != nil {
continue
}

// TODO: should be via New
versioned, err := info.Mapping.ConvertToVersion(info.Object, info.Mapping.GroupVersionKind.GroupVersion().String())
if err != nil {
patch.Err = err
continue
}

patch.Patch, patch.Err = strategicpatch.CreateTwoWayMergePatch(patch.Before, patch.After, versioned)
}
return patches
}
Loading