Skip to content

Commit

Permalink
Update glide lock
Browse files Browse the repository at this point in the history
Fix up after changes to libcalico API

Fix log
  • Loading branch information
Rob Brockbank committed Oct 20, 2016
1 parent 9c90260 commit 2d4a4ac
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 67 deletions.
41 changes: 21 additions & 20 deletions calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ func cmdAdd(args *skel.CmdArgs) error {

ConfigureLogging(conf.LogLevel)

workloadID, orchestratorID, err := GetIdentifiers(args)
workload, orchestrator, err := GetIdentifiers(args)
if err != nil {
return err
}

logger := CreateContextLogger(workloadID)
logger := CreateContextLogger(workload)

// Allow the hostname to be overridden by the network config
if conf.Hostname != "" {
hostname = conf.Hostname
}

logger.WithFields(log.Fields{
"OrchestratorID": orchestratorID,
"Hostname": hostname,
"Orchestrator": orchestrator,
"Node": hostname,
}).Info("Extracted identifiers")

calicoClient, err := CreateClient(conf)
Expand All @@ -80,9 +80,9 @@ func cmdAdd(args *skel.CmdArgs) error {
}
// Always check if there's an existing endpoint.
endpoints, err := calicoClient.WorkloadEndpoints().List(api.WorkloadEndpointMetadata{
Hostname: hostname,
OrchestratorID: orchestratorID,
WorkloadID: workloadID})
Node: hostname,
Orchestrator: orchestrator,
Workload: workload})
if err != nil {
return err
}
Expand All @@ -102,7 +102,7 @@ func cmdAdd(args *skel.CmdArgs) error {

// If running under Kubernetes then branch off into the kubernetes code, otherwise handle everything in this
// function.
if orchestratorID == "k8s" {
if orchestrator == "k8s" {
if result, err = k8s.CmdAddK8s(args, conf, hostname, calicoClient, endpoint); err != nil {
return err
}
Expand Down Expand Up @@ -148,9 +148,9 @@ func cmdAdd(args *skel.CmdArgs) error {
// 2) Create the endpoint object
endpoint = api.NewWorkloadEndpoint()
endpoint.Metadata.Name = args.IfName
endpoint.Metadata.Hostname = hostname
endpoint.Metadata.OrchestratorID = orchestratorID
endpoint.Metadata.WorkloadID = workloadID
endpoint.Metadata.Node = hostname
endpoint.Metadata.Orchestrator = orchestrator
endpoint.Metadata.Workload = workload
endpoint.Metadata.Labels = labels
endpoint.Spec.Profiles = []string{profileID}

Expand Down Expand Up @@ -222,7 +222,7 @@ func cmdAdd(args *skel.CmdArgs) error {
// Otherwise, incoming traffic is only allowed from profiles with the same tag.
fmt.Fprintf(os.Stderr, "Calico CNI creating profile: %s\n", conf.Name)
var inboundRules []api.Rule
if orchestratorID == "k8s" {
if orchestrator == "k8s" {
inboundRules = []api.Rule{{Action: "allow"}}
} else {
inboundRules = []api.Rule{{Action: "allow", Source: api.EntityRule{Tag: conf.Name}}}
Expand Down Expand Up @@ -255,22 +255,22 @@ func cmdDel(args *skel.CmdArgs) error {

ConfigureLogging(conf.LogLevel)

workloadID, orchestratorID, err := GetIdentifiers(args)
workload, orchestrator, err := GetIdentifiers(args)
if err != nil {
return err
}

logger := CreateContextLogger(workloadID)
logger := CreateContextLogger(workload)

// Allow the hostname to be overridden by the network config
if conf.Hostname != "" {
hostname = conf.Hostname
}

logger.WithFields(log.Fields{
"WorkloadID": workloadID,
"OrchestratorID": orchestratorID,
"Hostname": hostname,
"Workload": workload,
"Orchestrator": orchestrator,
"Node": hostname,
}).Info("Extracted identifiers")

// Always try to release the address. Don't deal with any errors till the endpoints are cleaned up.
Expand All @@ -289,9 +289,10 @@ func cmdDel(args *skel.CmdArgs) error {
}

if err := calicoClient.WorkloadEndpoints().Delete(api.WorkloadEndpointMetadata{
Hostname: hostname,
OrchestratorID: orchestratorID,
WorkloadID: workloadID}); err != nil {
Name: args.IfName,
Node: hostname,
Orchestrator: orchestrator,
Workload: workload}); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion calico_cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var _ = Describe("CalicoCni", func() {
// The endpoint is created in etcd
endpoint_path := GetEtcdMostRecentSubdir(fmt.Sprintf("/calico/v1/host/%s/workload/cni/%s", hostname, containerID))
Expect(endpoint_path).Should(ContainSubstring(containerID))
Expect(GetEtcdString(endpoint_path)).Should(MatchJSON(fmt.Sprintf(`{"state":"active","name":"cali%s","mac":"%s","profile_ids":["net1"],"ipv4_nets":["%s/32"],"ipv6_nets":[],"labels":{}}`, containerID, mac, ip)))
Expect(GetEtcdString(endpoint_path)).Should(MatchJSON(fmt.Sprintf(`{"state":"active","name":"cali%s","mac":"%s","profile_ids":["net1"],"ipv4_nets":["%s/32"],"ipv6_nets":[]}`, containerID, mac, ip)))

// Routes and interface on host - there's is nothing to assert on the routes since felix adds those.
//fmt.Println(Cmd("ip link show")) // Useful for debugging
Expand Down
65 changes: 28 additions & 37 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package: github.com/projectcalico/calico-cni
import:
- package: github.com/Sirupsen/logrus
- package: github.com/containernetworking/cni
version: 07a8a28637e97b22eb8dfe710eeae1344f69d16e
subpackages:
- pkg/ip
- pkg/ipam
Expand All @@ -21,6 +22,7 @@ import:
- lib/net
- package: github.com/vishvananda/netlink
- package: k8s.io/client-go
version: 93fcd402979cfad8a7151f96e016416947c6a3cb
subpackages:
- 1.4/kubernetes
- 1.4/tools/clientcmd
14 changes: 7 additions & 7 deletions k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ func CmdAddK8s(args *skel.CmdArgs, conf utils.NetConf, hostname string, calicoCl

utils.ConfigureLogging(conf.LogLevel)

workloadID, orchestratorID, err := utils.GetIdentifiers(args)
workload, orchestrator, err := utils.GetIdentifiers(args)
if err != nil {
return nil, err
}
logger := utils.CreateContextLogger(workloadID)
logger := utils.CreateContextLogger(workload)
logger.WithFields(log.Fields{
"OrchestratorID": orchestratorID,
"Hostname": hostname,
"Orchestrator": orchestrator,
"Node": hostname,
}).Info("Extracted identifiers")

if endpoint != nil {
Expand Down Expand Up @@ -98,9 +98,9 @@ func CmdAddK8s(args *skel.CmdArgs, conf utils.NetConf, hostname string, calicoCl
// Create the endpoint object and configure it
endpoint = api.NewWorkloadEndpoint()
endpoint.Metadata.Name = args.IfName
endpoint.Metadata.Hostname = hostname
endpoint.Metadata.OrchestratorID = orchestratorID
endpoint.Metadata.WorkloadID = workloadID
endpoint.Metadata.Node = hostname
endpoint.Metadata.Orchestrator = orchestrator
endpoint.Metadata.Workload = workload
endpoint.Metadata.Labels = make(map[string]string)

// Set the profileID according to whether Kubernetes policy is required. If it's not, then just use the network
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ func ConfigureLogging(logLevel string) {
}

// Create a logger which always includes common fields
func CreateContextLogger(workloadID string) *log.Entry {
func CreateContextLogger(workload string) *log.Entry {
// A common pattern is to re-use fields between logging statements by re-using
// the logrus.Entry returned from WithFields()
contextLogger := log.WithFields(log.Fields{
"WorkloadID": workloadID,
"Workload": workload,
})

return contextLogger
Expand Down

0 comments on commit 2d4a4ac

Please sign in to comment.