Skip to content

Commit

Permalink
redefine labels and meta
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Sep 4, 2018
1 parent 2ad7149 commit 6dfcaab
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 324 deletions.
7 changes: 3 additions & 4 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,17 @@ func (c *Calcium) makeContainerOptions(index int, quota types.CPUMap, opts *type

containerLogConfig := enginecontainer.LogConfig{Type: logConfig.Type, Config: logConfig.Config}

// labels
// basic labels, and set meta in opts to labels
// basic labels, bind to EruMeta
containerLabels := map[string]string{
cluster.ERUMark: "1",
cluster.ERUMeta: utils.EncodeMetaInLabel(&types.ContainerMeta{
cluster.ERUMeta: utils.EncodeMetaInLabel(&types.EruMeta{
Publish: opts.Entrypoint.Publish,
HealthCheck: entry.HealthCheck,
}),
}

// 接下来是meta
for key, value := range opts.Meta {
for key, value := range opts.Labels {
containerLabels[key] = value
}

Expand Down
2 changes: 1 addition & 1 deletion cluster/calcium/replace_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (c *Calcium) doReplaceContainer(
return nil, removeMessage, err
}

if !utils.FilterContainer(containerJSON.Config.Labels, opts.Labels) {
if !utils.FilterContainer(containerJSON.Config.Labels, opts.FilterLabels) {
return nil, removeMessage, types.ErrNotFitLabels
}

Expand Down
467 changes: 234 additions & 233 deletions rpc/gen/core.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rpc/gen/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ message DeployOptions {
string user = 16;
bool debug = 17;
bool openStdin = 18;
map<string, string> meta = 19;
map<string, string> labels = 19;
map<string, string> nodelabels = 20;
string deploy_method = 21;
map<string, bytes> data = 22;
Expand All @@ -276,7 +276,7 @@ message DeployOptions {
message ReplaceOptions {
DeployOptions deployOpt = 1;
bool force = 2;
map<string, string> labels = 3;
map<string, string> filter_labels = 3;
}

message RemoveImageOptions {
Expand Down
148 changes: 74 additions & 74 deletions rpc/gen/core_pb2.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (v *Vibranium) ReplaceContainer(opts *pb.ReplaceOptions, stream pb.CoreRPC_
return err
}
//这里考虑用全局 Background
replaceOpts := &types.ReplaceOptions{DeployOptions: *deployOpts, Force: opts.Force, Labels: opts.Labels}
replaceOpts := &types.ReplaceOptions{DeployOptions: *deployOpts, Force: opts.Force, FilterLabels: opts.FilterLabels}
ch, err := v.cluster.ReplaceContainer(context.Background(), replaceOpts)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion rpc/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func toCoreDeployOptions(d *pb.DeployOptions) (*types.DeployOptions, error) {
User: d.User,
Debug: d.Debug,
OpenStdin: d.OpenStdin,
Meta: d.Meta,
Labels: d.Labels,
NodeLabels: d.Nodelabels,
DeployMethod: d.DeployMethod,
Data: data,
Expand Down
4 changes: 2 additions & 2 deletions types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ type DeployStatus struct {
ID string
}

// ContainerMeta bind meta info store in labels
type ContainerMeta struct {
// EruMeta bind meta info store in labels
type EruMeta struct {
Publish []string
HealthCheck *HealthCheck
}
6 changes: 3 additions & 3 deletions types/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type DeployOptions struct {
User string // User for container
Debug bool // debug mode, use syslog as log driver
OpenStdin bool // OpenStdin for container
Meta map[string]string // Meta for containers
Labels map[string]string // Labels for containers
NodeLabels map[string]string // NodeLabels for filter node
DeployMethod string // Deploy method
Data map[string]*bytes.Buffer // For additional file data
Expand Down Expand Up @@ -60,6 +60,6 @@ type ListContainersOptions struct {
// ReplaceOptions for replace container
type ReplaceOptions struct {
DeployOptions
Force bool
Labels map[string]string
Force bool
FilterLabels map[string]string
}
6 changes: 3 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func DecodePublishInfo(info map[string]string) map[string][]string {
}

// EncodeMetaInLabel encode meta to json
func EncodeMetaInLabel(meta *types.ContainerMeta) string {
func EncodeMetaInLabel(meta *types.EruMeta) string {
data, err := json.Marshal(meta)
if err != nil {
log.Errorf("[EncodeMetaInLabel] Encode meta failed %v", err)
Expand All @@ -226,8 +226,8 @@ func EncodeMetaInLabel(meta *types.ContainerMeta) string {
}

// DecodeMetaInLabel get meta from label and decode it
func DecodeMetaInLabel(labels map[string]string) *types.ContainerMeta {
meta := &types.ContainerMeta{}
func DecodeMetaInLabel(labels map[string]string) *types.EruMeta {
meta := &types.EruMeta{}
metastr, ok := labels[cluster.ERUMeta]
if ok {
if err := json.Unmarshal([]byte(metastr), meta); err != nil {
Expand Down

0 comments on commit 6dfcaab

Please sign in to comment.