Skip to content
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

Merged
merged 2 commits into from
Jan 25, 2017

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Jan 24, 2017

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 24, 2017
@liggitt
Copy link
Member Author

liggitt commented Jan 24, 2017

cc @thockin @MrHohn

Copy link
Contributor

@GheRivero GheRivero left a 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")
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@liggitt liggitt force-pushed the configmap branch 2 times, most recently from 3e122b9 to ba472f4 Compare January 24, 2017 18:41
@liggitt
Copy link
Member Author

liggitt commented Jan 24, 2017

added tests for the file-based config

@bowei bowei self-assigned this Jan 24, 2017
Copy link
Member

@bowei bowei left a 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 {
Copy link
Member

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...")
}

Copy link
Member Author

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 != "":
Copy link
Member

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?

Copy link
Member Author

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.")
Copy link
Member

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`.
Copy link
Member

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 {
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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 @@
/*
Copy link
Member

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

@liggitt
Copy link
Member Author

liggitt commented Jan 24, 2017

comments addressed

@liggitt
Copy link
Member Author

liggitt commented Jan 24, 2017

It would be preferable to just have just expose NewConfigMapSync and NewFileSync constructors for Sync and hide the SyncSource and SyncResult from outside altogether.

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 {
Copy link
Member

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.

Copy link
Member Author

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",
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@MrHohn
Copy link
Member

MrHohn commented Jan 25, 2017

Thanks for the helps! LGTM @bowei

@bowei bowei merged commit 8a21972 into kubernetes:master Jan 25, 2017
@liggitt
Copy link
Member Author

liggitt commented Jan 25, 2017

thanks! what's the timeframe or process for getting a version of the image made with this?

@bowei
Copy link
Member

bowei commented Jan 25, 2017

uploading right now...

@bowei
Copy link
Member

bowei commented Jan 25, 2017

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.

@bowei
Copy link
Member

bowei commented Jan 25, 2017

gcr.io/google_containers/k8s-dns-dnsmasq-amd64:1.12.0
gcr.io/google_containers/k8s-dns-dnsmasq-arm:1.12.0
gcr.io/google_containers/k8s-dns-dnsmasq-arm64:1.12.0
gcr.io/google_containers/k8s-dns-dnsmasq-ppc64le:1.12.0
gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.12.0
gcr.io/google_containers/k8s-dns-kube-dns-arm:1.12.0
gcr.io/google_containers/k8s-dns-kube-dns-arm64:1.12.0
gcr.io/google_containers/k8s-dns-kube-dns-ppc64le:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-amd64:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-arm:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-arm64:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-e2e-amd64:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-e2e-arm:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-e2e-arm64:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-e2e-ppc64le:1.12.0
gcr.io/google_containers/k8s-dns-sidecar-ppc64le:1.12.0

@liggitt liggitt deleted the configmap branch January 26, 2017 21:44
k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Feb 7, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants