-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
623 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
ROOT_DIR = $(CURDIR) | ||
OUTPUT_DIR = $(ROOT_DIR)/_output | ||
BIN_DIR = $(OUTPUT_DIR)/bin | ||
REPO_PREFIX = yunion.io/x/kubecomps | ||
|
||
GO_BUILD := go build | ||
|
||
CMDS := $(shell find $(ROOT_DIR)/cmd -mindepth 1 -maxdepth 1 -type d) | ||
|
||
REGISTRY ?= "registry.cn-beijing.aliyuncs.com/yunionio" | ||
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \ | ||
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8) | ||
|
||
build: clean | ||
@for CMD in $(CMDS); do \ | ||
echo build $$CMD; \ | ||
$(GO_BUILD) -o $(BIN_DIR)/`basename $${CMD}` $$CMD; \ | ||
done | ||
|
||
prepare_dir: | ||
@mkdir -p $(BIN_DIR) | ||
|
||
cmd/%: prepare_dir | ||
$(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@ | ||
|
||
image: | ||
DEBUG=$(DEBUG) ARCH=$(ARCH) TAG=$(VERSION) REGISTRY=$(REGISTRY) $(ROOT_DIR)/scripts/docker_push.sh $(filter-out $@,$(MAKECMDGOALS)) | ||
|
||
clean: | ||
@rm -rf $(OUTPUT_DIR) | ||
|
||
.PHONY: build clean | ||
%: | ||
@: | ||
|
||
.PHONY: build clean image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM registry.cn-beijing.aliyuncs.com/yunionio/onecloud-base:v0.2 | ||
|
||
ADD ./_output/alpine-build/bin/calico-node-agent /opt/yunion/bin/calico-node-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
|
||
"github.com/fsnotify/fsnotify" | ||
|
||
"yunion.io/x/log" | ||
"yunion.io/x/pkg/errors" | ||
) | ||
|
||
type WatchHandler interface { | ||
OnCreate(ctx context.Context, pathName string) | ||
OnUpdate(ctx context.Context, pathName string) | ||
OnDelete(ctx context.Context, pathName string) | ||
OnError(ctx context.Context, err error) | ||
} | ||
|
||
func StartWatcher(ctx context.Context, configFile string, handler WatchHandler) error { | ||
watcher, err := fsnotify.NewWatcher() | ||
if err != nil { | ||
return errors.Wrap(err, "fsnotify.NewWatcher") | ||
} | ||
defer watcher.Close() | ||
|
||
cfBasename := filepath.Base(configFile) | ||
done := make(chan bool) | ||
go func() { | ||
for { | ||
select { | ||
case event, ok := <-watcher.Events: | ||
if !ok { | ||
log.Errorf("Get events from watcher not ok") | ||
return | ||
} | ||
|
||
curBasename := filepath.Base(event.Name) | ||
if cfBasename != curBasename { | ||
log.Debugf("ignore event %s", event) | ||
continue | ||
} | ||
|
||
if event.Op&fsnotify.Chmod == fsnotify.Chmod { | ||
// not care about CHMOD | ||
continue | ||
} | ||
|
||
log.Infof("Watcher event happened: %s", event) | ||
|
||
if event.Op&fsnotify.Create == fsnotify.Create { | ||
handler.OnCreate(ctx, event.Name) | ||
} else if event.Op&fsnotify.Write == fsnotify.Write { | ||
handler.OnUpdate(ctx, event.Name) | ||
} else if event.Op&fsnotify.Remove == fsnotify.Remove { | ||
handler.OnDelete(ctx, event.Name) | ||
} else { | ||
log.Warningf("Unhandle watcher event: %s", event) | ||
} | ||
|
||
case err, ok := <-watcher.Errors: | ||
if !ok { | ||
log.Errorf("Get errors from watcher not ok") | ||
return | ||
} | ||
handler.OnError(ctx, err) | ||
} | ||
} | ||
}() | ||
|
||
dirname := filepath.Dir(configFile) | ||
if err := watcher.Add(dirname); err != nil { | ||
return errors.Wrapf(err, "watch config file dir %s", dirname) | ||
} | ||
<-done | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.