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

sync restrictedCIDRs with install-config #74

Merged

Conversation

sanchezl
Copy link
Contributor

@sanchezl sanchezl commented Oct 16, 2018

Enables the cluster-kube-apiserver-operator to receive notifications of changes to the cluster-config-v1 ConfigMap in the kube-system namespace, from which some CIDRs are extracted, i.e:

data:
  install-config:
    networking:
    podCIDR: 10.2.0.0/16
    serviceCIDR: 10.3.0.0/16

Adds the discovered CIDRs to the restrictedCIDRs array to the cluster kube apiserver's config. e.g.:

admissionPluginConfig:
  openshift.io/RestrictedEndpointsAdmission:
    configuration:
      restrictedCIDRs:
        - 10.3.0.0/16 # ServiceCIDR
        - 10.2.0.0/16 # ClusterCIDR

Resolves #50

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 16, 2018
@deads2k
Copy link
Contributor

deads2k commented Oct 16, 2018

Towards resolving #50

give me a better description

@sanchezl WIP pulls should have [WIP] in the description so they can't auto-merge. please add it

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"gopkg.in/yaml.v2"
Copy link
Contributor

Choose a reason for hiding this comment

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

imports go

  1. core library
  2. not core, not kube, not openshift
  3. kube
  4. openshift.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I've notice use of gopkg.in/yaml.v2 and github.com/ghodss/yaml in the openshift/* repositories. Any guidance on when to pick one over another?

@@ -25,6 +26,7 @@ import (

operatorconfigclientv1alpha1 "github.com/openshift/cluster-kube-apiserver-operator/pkg/generated/clientset/versioned/typed/kubeapiserver/v1alpha1"
operatorconfiginformerv1alpha1 "github.com/openshift/cluster-kube-apiserver-operator/pkg/generated/informers/externalversions/kubeapiserver/v1alpha1"
installer "github.com/openshift/installer/pkg/types"
Copy link
Contributor

Choose a reason for hiding this comment

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

no. You may not import this package into the project.

return fmt.Errorf("error retieving cluster config: %s", err)
}

// get install-config from cluster config
Copy link
Contributor

Choose a reason for hiding this comment

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

seriously? Delete useless comment.

@@ -86,6 +88,45 @@ func (c ConfigObserver) sync() error {
unstructured.SetNestedStringSlice(observedConfig, etcdURLs, "storageConfig", "urls")
}

// observe configuration from cluster-config-v1
Copy link
Contributor

Choose a reason for hiding this comment

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

make this comment useful. You're collecting some CIDR from the clusterconfig.

}

// set observed values
// admissionPluginConfig:
Copy link
Contributor

Choose a reason for hiding this comment

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

wow. One the one hand I'm glad I now know. On the other hand, that's going to be a bitch to maintain.

@squeed @knobunc does anyone use this admission plugin to control ranges other than these two CIDRs? Should they be able to?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I know of... but who knows what people have configured.

@deads2k
Copy link
Contributor

deads2k commented Oct 16, 2018

notice how NewConfigObserver is called. Go to its callsite and wire through an informer that watches the kube-system namespace. Then update NewConfigObserver to add an event handler for updates to configmaps from that namespace.

@deads2k
Copy link
Contributor

deads2k commented Oct 16, 2018

/retest

@sanchezl sanchezl changed the title sync restrictedCIDRs with install-config [WIP] sync restrictedCIDRs with install-config Oct 16, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 16, 2018
@sanchezl sanchezl force-pushed the sync_restricted_cidrs branch 3 times, most recently from 1c51f55 to df19478 Compare October 16, 2018 20:33
// podCIDR: 10.2.0.0/16
// serviceCIDR: 10.3.0.0/16
restrictedCIDRs := []string{}
if networking, ok := installConfig["networking"].(map[string]string); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this to always panic. Please add a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect this to always panic. Please add a test.

err, always fail. Is it really particular?

// serviceCIDR: 10.3.0.0/16
restrictedCIDRs := []string{}
if networking, ok := installConfig["networking"].(map[string]string); ok {
if cidr, ok := networking["podCIDR"]; ok && cidr != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

ok is unnecessary to check here, right?

// - 10.3.0.0/16 # ServiceCIDR
// - 10.2.0.0/16 # ClusterCIDR
// TODO should I just skip this if no CIDRs are found?
unstructured.SetNestedStringSlice(observedConfig, restrictedCIDRs,
Copy link
Contributor

Choose a reason for hiding this comment

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

only do this if you have more than zero restricted CIDRs

@deads2k
Copy link
Contributor

deads2k commented Oct 16, 2018

Think of a way to factor this that makes sense for to extend assuming we observe about 10 values. Don't spend more than an hour.....

And let me know if you're stuck on the wiring bit.

@squeed
Copy link
Contributor

squeed commented Oct 16, 2018

FYI, I will need to refactor the configuration object to support multiple ClusterCIDRs.

@deads2k
Copy link
Contributor

deads2k commented Oct 17, 2018

FYI, I will need to refactor the configuration object to support multiple ClusterCIDRs.

@squeed when that happens, please give us a heads up.

@sanchezl sanchezl force-pushed the sync_restricted_cidrs branch 2 times, most recently from 36db284 to 90ffa2a Compare October 17, 2018 15:46
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 17, 2018
if observedConfig, err = c.observeEtcdEndpoints(observedConfig); err != nil {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

no newline

observedConfig := map[string]interface{}{}
var err error

if observedConfig, err = c.observeEtcdEndpoints(observedConfig); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't do this. If you are assigning to a value that escapes the block, you don't do it in the block.

t.Fatal("expected 2 entries in restrictedCIDRs")
}
for _, cidr := range []string{podCIDR, serviceCIDR} {
if func() int {
Copy link
Contributor

Choose a reason for hiding this comment

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

no

operatorConfigClient.KubeapiserverV1alpha1(),
kubeClient.AppsV1(),
kubeClient.CoreV1(),
kubeClient.RbacV1(),
)

kubeInformersEtcdNamespaced := informers.NewFilteredSharedInformerFactory(kubeClient, 10*time.Minute, etcdNamespaceName, nil)
kubeInformersForKubeSystemNamespace := informers.NewSharedInformerFactoryWithOptions(kubeClient, 10*time.Minute, informers.WithNamespace("kube-system"))
Copy link
Contributor

Choose a reason for hiding this comment

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

construct all in the same spot (line 35ish) please

@sanchezl sanchezl force-pushed the sync_restricted_cidrs branch 4 times, most recently from 430b6e9 to acc7d7d Compare October 18, 2018 15:39
t.Fatal(err)
}
if restrictedCIDRs[0] != podCIDR {
t.Fail()
Copy link
Contributor

Choose a reason for hiding this comment

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

print me out hte actual value in the last two conditions.

Namespace: "kube-system",
},
Data: map[string]string{
"install-config": fmt.Sprintf("networking:\n podCIDR: %s\n serviceCIDR: %s\n", podCIDR, serviceCIDR),
Copy link
Contributor

@deads2k deads2k Oct 18, 2018

Choose a reason for hiding this comment

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

just saw this was missed. Just use plus signs

)

func TestObserveClusterConfig(t *testing.T) {

Copy link
Contributor

Choose a reason for hiding this comment

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

and while you're updating, you need to kill your whitespace bunny that keeps putting these here.

@sanchezl sanchezl force-pushed the sync_restricted_cidrs branch 2 times, most recently from 3fcdcfc to 7df2a0c Compare October 18, 2018 17:59
@deads2k
Copy link
Contributor

deads2k commented Oct 18, 2018

/lgtm

@sttts
Copy link
Contributor

sttts commented Oct 19, 2018

/lgtm
/approve

Prow had issues.

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 19, 2018
@sttts
Copy link
Contributor

sttts commented Oct 19, 2018

@sanchezl we need the same during the bootstrapping phase via the render command. Can you find out whether we have access to the cluster config already at that stage? This code is executed at that point: https://github.com/openshift/installer/blob/master/pkg/asset/ignition/bootstrap/content/bootkube.go#L31

It's a text/template. So maybe we have the cluster config in one form or another around to be plugged in, or even as file on the bootstrap node.

@deads2k
Copy link
Contributor

deads2k commented Oct 19, 2018

rebase requried

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 22, 2018
@deads2k
Copy link
Contributor

deads2k commented Oct 23, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, sanchezl, sttts

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants