Пример #1
0
// Merge merges a flagset into a service spec.
func Merge(cmd *cobra.Command, spec *api.ServiceSpec, c api.ControlClient) error {
	flags := cmd.Flags()

	if flags.Changed("name") {
		name, err := flags.GetString("name")
		if err != nil {
			return err
		}
		spec.Annotations.Name = name
	}

	if flags.Changed("label") {
		labels, err := flags.GetStringSlice("label")
		if err != nil {
			return err
		}
		spec.Annotations.Labels = map[string]string{}
		for _, l := range labels {
			parts := strings.SplitN(l, "=", 2)
			if len(parts) != 2 {
				return fmt.Errorf("malformed label: %s", l)
			}
			spec.Annotations.Labels[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
		}
	}

	if err := parseMode(flags, spec); err != nil {
		return err
	}

	if err := parseContainer(flags, spec); err != nil {
		return err
	}

	if err := parseResource(flags, spec); err != nil {
		return err
	}

	if err := parsePorts(flags, spec); err != nil {
		return err
	}

	if err := parseNetworks(cmd, spec, c); err != nil {
		return err
	}

	if err := parseRestart(flags, spec); err != nil {
		return err
	}

	if err := parseUpdate(flags, spec); err != nil {
		return err
	}

	if err := parsePlacement(flags, spec); err != nil {
		return err
	}

	if err := parseBind(flags, spec); err != nil {
		return err
	}

	if err := parseVolume(flags, spec); err != nil {
		return err
	}

	if err := parseTmpfs(flags, spec); err != nil {
		return err
	}

	driver, err := common.ParseLogDriverFlags(flags)
	if err != nil {
		return err
	}
	spec.Task.LogDriver = driver

	return nil
}
Пример #2
0
					return errors.New("--rotate-join-token flag must be followed by 'worker' or 'manager'")
				}
			}
			if flags.Changed("autolock") {
				spec.EncryptionConfig.AutoLockManagers, err = flags.GetBool("autolock")
				if err != nil {
					return err
				}
			}
			rotateUnlockKey, err := flags.GetBool("rotate-unlock-key")
			if err != nil {
				return err
			}
			rotation.ManagerUnlockKey = rotateUnlockKey

			driver, err := common.ParseLogDriverFlags(flags)
			if err != nil {
				return err
			}
			spec.TaskDefaults.LogDriver = driver

			r, err := c.UpdateCluster(common.Context(cmd), &api.UpdateClusterRequest{
				ClusterID:      cluster.ID,
				ClusterVersion: &cluster.Meta.Version,
				Spec:           spec,
				Rotation:       rotation,
			})
			if err != nil {
				return err
			}
			fmt.Println(r.Cluster.ID)