本文整理汇总了Golang中github.com/qingyuancloud/QingYuan/pkg/qingctl/cmd/util.Factory.PrintObject方法的典型用法代码示例。如果您正苦于以下问题:Golang Factory.PrintObject方法的具体用法?Golang Factory.PrintObject怎么用?Golang Factory.PrintObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/qingyuancloud/QingYuan/pkg/qingctl/cmd/util.Factory
的用法示例。
在下文中一共展示了Factory.PrintObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func Run(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string) error {
if os.Args[1] == "run-container" {
printDeprecationWarning("run", "run-container")
}
if len(args) != 1 {
return cmdutil.UsageError(cmd, "NAME is required for run")
}
namespace, err := f.DefaultNamespace()
if err != nil {
return err
}
client, err := f.Client()
if err != nil {
return err
}
generatorName := cmdutil.GetFlagString(cmd, "generator")
generator, found := f.Generator(generatorName)
if !found {
return cmdutil.UsageError(cmd, fmt.Sprintf("Generator: %s not found.", generator))
}
names := generator.ParamNames()
params := qingctl.MakeParams(cmd, names)
params["name"] = args[0]
err = qingctl.ValidateParams(names, params)
if err != nil {
return err
}
controller, err := generator.Generate(params)
if err != nil {
return err
}
inline := cmdutil.GetFlagString(cmd, "overrides")
if len(inline) > 0 {
controller, err = cmdutil.Merge(controller, inline, "ReplicationController")
if err != nil {
return err
}
}
// TODO: extract this flag to a central location, when such a location exists.
if !cmdutil.GetFlagBool(cmd, "dry-run") {
controller, err = client.ReplicationControllers(namespace).Create(controller.(*api.ReplicationController))
if err != nil {
return err
}
}
return f.PrintObject(cmd, controller, out)
}
示例2: RunRollingUpdate
//.........这里部分代码省略.........
return cmdutil.UsageError(cmd, "%s contains a %s not a ReplicationController", filename, kind)
}
glog.V(4).Infof("Object %#v is not a ReplicationController", obj)
return cmdutil.UsageError(cmd, "%s does not specify a valid ReplicationController", filename)
}
}
// If the --image option is specified, we need to create a new rc with at least one different selector
// than the old rc. This selector is the hash of the rc, which will differ because the new rc has a
// different image.
if len(image) != 0 {
keepOldName = len(args) == 1
newName := findNewName(args, oldRc)
if newRc, err = qingctl.LoadExistingNextReplicationController(client, cmdNamespace, newName); err != nil {
return err
}
if newRc != nil {
fmt.Fprintf(out, "Found existing update in progress (%s), resuming.\n", newRc.Name)
} else {
newRc, err = qingctl.CreateNewControllerFromCurrentController(client, cmdNamespace, oldName, newName, image, deploymentKey)
if err != nil {
return err
}
}
// Update the existing replication controller with pointers to the 'next' controller
// and adding the <deploymentKey> label if necessary to distinguish it from the 'next' controller.
oldHash, err := api.HashObject(oldRc, client.Codec)
if err != nil {
return err
}
oldRc, err = qingctl.UpdateExistingReplicationController(client, oldRc, cmdNamespace, newRc.Name, deploymentKey, oldHash, out)
if err != nil {
return err
}
}
if oldName == newRc.Name {
return cmdutil.UsageError(cmd, "%s cannot have the same name as the existing ReplicationController %s",
filename, oldName)
}
updater := qingctl.NewRollingUpdater(newRc.Namespace, updaterClient)
// To successfully pull off a rolling update the new and old rc have to differ
// by at least one selector. Every new pod should have the selector and every
// old pod should not have the selector.
var hasLabel bool
for key, oldValue := range oldRc.Spec.Selector {
if newValue, ok := newRc.Spec.Selector[key]; ok && newValue != oldValue {
hasLabel = true
break
}
}
if !hasLabel {
return cmdutil.UsageError(cmd, "%s must specify a matching key with non-equal value in Selector for %s",
filename, oldName)
}
// TODO: handle scales during rolling update
if newRc.Spec.Replicas == 0 {
newRc.Spec.Replicas = oldRc.Spec.Replicas
}
if dryrun {
oldRcData := &bytes.Buffer{}
if err := f.PrintObject(cmd, oldRc, oldRcData); err != nil {
return err
}
newRcData := &bytes.Buffer{}
if err := f.PrintObject(cmd, newRc, newRcData); err != nil {
return err
}
fmt.Fprintf(out, "Rolling from:\n%s\nTo:\n%s\n", string(oldRcData.Bytes()), string(newRcData.Bytes()))
return nil
}
updateCleanupPolicy := qingctl.DeleteRollingUpdateCleanupPolicy
if keepOldName {
updateCleanupPolicy = qingctl.RenameRollingUpdateCleanupPolicy
}
config := &qingctl.RollingUpdaterConfig{
Out: out,
OldRc: oldRc,
NewRc: newRc,
UpdatePeriod: period,
Interval: interval,
Timeout: timeout,
CleanupPolicy: updateCleanupPolicy,
}
if cmdutil.GetFlagBool(cmd, "rollback") {
qingctl.AbortRollingUpdate(config)
client.ReplicationControllers(config.NewRc.Namespace).Update(config.NewRc)
}
err = updater.Update(config)
if err != nil {
return err
}
if keepOldName {
fmt.Fprintf(out, "%s\n", oldName)
} else {
fmt.Fprintf(out, "%s\n", newRc.Name)
}
return nil
}
示例3: RunExpose
//.........这里部分代码省略.........
// Get the generator, setup and validate all required parameters
generatorName := cmdutil.GetFlagString(cmd, "generator")
generator, found := f.Generator(generatorName)
if !found {
return cmdutil.UsageError(cmd, fmt.Sprintf("generator %q not found.", generatorName))
}
names := generator.ParamNames()
params := qingctl.MakeParams(cmd, names)
params["default-name"] = info.Name
if s, found := params["selector"]; !found || len(s) == 0 || cmdutil.GetFlagInt(cmd, "port") < 1 {
if len(s) == 0 {
s, err := f.PodSelectorForObject(inputObject)
if err != nil {
return err
}
params["selector"] = s
}
noPorts := true
for _, param := range names {
if param.Name == "port" {
noPorts = false
break
}
}
if cmdutil.GetFlagInt(cmd, "port") < 0 && !noPorts {
ports, err := f.PortsForObject(inputObject)
if err != nil {
return err
}
switch len(ports) {
case 0:
return cmdutil.UsageError(cmd, "couldn't find a suitable port via --port flag or introspection")
case 1:
params["port"] = ports[0]
default:
return cmdutil.UsageError(cmd, "more than one port to choose from, please explicitly specify a port using the --port flag.")
}
}
}
if cmdutil.GetFlagBool(cmd, "create-external-load-balancer") {
params["create-external-load-balancer"] = "true"
}
if len(params["labels"]) == 0 {
labels, err := f.LabelsForObject(inputObject)
if err != nil {
return err
}
params["labels"] = qingctl.MakeLabels(labels)
}
if v := cmdutil.GetFlagString(cmd, "type"); v != "" {
params["type"] = v
}
err = qingctl.ValidateParams(names, params)
if err != nil {
return err
}
// Expose new object
object, err := generator.Generate(params)
if err != nil {
return err
}
inline := cmdutil.GetFlagString(cmd, "overrides")
if len(inline) > 0 {
object, err = cmdutil.Merge(object, inline, mapping.Kind)
if err != nil {
return err
}
}
// TODO: extract this flag to a central location, when such a location exists.
if !cmdutil.GetFlagBool(cmd, "dry-run") {
resourceMapper := &resource.Mapper{typer, mapper, f.ClientMapperForCommand()}
info, err := resourceMapper.InfoForObject(object)
if err != nil {
return err
}
data, err := info.Mapping.Codec.Encode(object)
if err != nil {
return err
}
_, err = resource.NewHelper(info.Client, info.Mapping).Create(namespace, false, data)
if err != nil {
return err
}
}
if cmdutil.GetFlagBool(cmd, "create-external-load-balancer") {
msg := fmt.Sprintf(`
An external load-balanced service was created. On many platforms (e.g. Google Compute Engine),
you will also need to explicitly open a firewall rule for the service port (%d) to serve traffic.
See https://github.com/qingyuancloud/QingYuan/tree/master/docs/services-firewall.md for more details.
`, cmdutil.GetFlagInt(cmd, "port"))
out.Write([]byte(msg))
}
return f.PrintObject(cmd, object, out)
}