-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pulling config from a directory #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit
glog.V(0).Infof("Using configuration read from directory: %v", config.ConfigDir, config.ConfigPeriod) | ||
syncSource := dnsconfig.NewFileSyncSource(config.ConfigDir, config.ConfigPeriod) | ||
configSync = dnsconfig.NewSync(syncSource) | ||
default: | ||
glog.V(0).Infof("ConfigMap not configured, using values from command line flags") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be updated to inform that ConfigDir is neither configured
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
3e122b9
to
ba472f4
Compare
added tests for the file-based config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for taking care of this
config.ConfigMapNs, config.ConfigMap) | ||
configSync = dnsconfig.NewSync( | ||
kubeClient, config.ConfigMapNs, config.ConfigMap) | ||
switch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
if config.ConfigMap != "" && config.ConfigDir != "" {
glog.V(0).Warnf("Both ConfigMap and ConfigDir set...")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added check for both below
configSync = dnsconfig.NewSync( | ||
kubeClient, config.ConfigMapNs, config.ConfigMap) | ||
switch { | ||
case config.ConfigMap != "": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to prefer ConfigDir in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I'd error... they need to pick one
@@ -166,4 +172,9 @@ func (s *KubeDNSConfig) AddFlags(fs *pflag.FlagSet) { | |||
"dynamically adjustable configuration.") | |||
fs.DurationVar(&s.InitialSyncTimeout, "initial-sync-timeout", s.InitialSyncTimeout, | |||
"Timeout for initial resource sync.") | |||
|
|||
fs.StringVar(&s.ConfigDir, "config-dir", s.ConfigDir, | |||
"directory to read config values from.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add something like ". Only one of config-map or config-dir should be set"
Once() (SyncResult, error) | ||
Periodic() <-chan SyncResult | ||
} | ||
|
||
// NewSync for ConfigMap from namespace `ns` and `name`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment needs to be updated
Data map[string]string | ||
} | ||
|
||
type SyncSource interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the same as Sync interface above? Why have another layer here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source just gets the data (from the API or from the disk)
that's logically distinct from deduping on version, parsing and validating that data into a config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make SyncSource and SyncResult package private in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, they get returned and used by the app package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think SyncResult for sure does not need to be exposed. I just tried it with your patch and there isn't an issue.
It would be preferable to just have just expose NewConfigMapSync and NewFileSync constructors for SYnc and hide the SyncSource and SyncResult from outside altogether.
@@ -0,0 +1,120 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we name this sync_configmap.go? sync_api would refer to "the sync API" in my mind
comments addressed |
sounds good, updated. |
|
||
// should return error if non-utf8 data is encountered | ||
// https://en.wikipedia.org/wiki/UTF-8#Codepage_layout | ||
if err := ioutil.WriteFile(filepath.Join(testDir, "binary"), []byte{192}, os.FileMode(0755)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, does data
in ConfigMap only contain UTF-8? I used to think that is only true for key
, which got reflected as path here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's map[string]string
, not map[string][]byte
, so it should only be utf-8 data
t.Fatalf("expected no error, got: %v", err) | ||
} | ||
expectedResult := syncResult{ | ||
Version: "d56592d659b731bdf7979b45644cba0ce80cc672ec7d30899757b4ad892c7360", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get this hash programmably?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Thanks for the helps! LGTM @bowei |
thanks! what's the timeframe or process for getting a version of the image made with this? |
uploading right now... |
I have plans to make the releases automated, but haven't gotten around to it. There are some issues with automation google_containers auth tokens which I have to resolve. |
gcr.io/google_containers/k8s-dns-dnsmasq-amd64:1.12.0 |
Automatic merge from submit-queue (batch tested with PRs 40382, 41060) Make kube-dns mount optional configmap Switches add-on templates to use an optional mounted configmap for dns Uses options added in kubernetes/dns#39 Blocks #38816
now that optional configmaps are possible, kube-dns should support pulling config from a mounted directory
this PR refactors the existing API-based configmap source and adds a directory-based source
c.f.
kubernetes/kubernetes#36775 (comment)
kubernetes/kubernetes#38816
kubernetes/kubernetes#39981