Skip to content

Commit

Permalink
define static ip config (#1263)
Browse files Browse the repository at this point in the history
* unwire pod cidrs command line flag

* define static ip config

* remove refs to pod cidr flag

* ignore cyclomatic complexity of aws getconfig
  • Loading branch information
PratikDeoghare authored Apr 26, 2022
1 parent c4a4228 commit 99a8a3f
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 26 deletions.
11 changes: 3 additions & 8 deletions cmd/machine-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var (
nodeRegistryMirrors string
nodePauseImage string
nodeContainerRuntime string
podCIDRs string
podCIDR string
nodePortRange string
nodeRegistryCredentialsSecret string
nodeContainerdRegistryMirrors = containerruntime.RegistryMirrorsFlags{}
Expand Down Expand Up @@ -127,9 +127,6 @@ type controllerRunOptions struct {

useOSM bool

// Assigns the POD networks that will be allocated.
podCIDRs []string

// A port range to reserve for services with NodePort visibility
nodePortRange string
}
Expand All @@ -140,7 +137,7 @@ func main() {
klog.InitFlags(nil)
// This is also being registered in kubevirt.io/kubevirt/pkg/kubecli/kubecli.go so
// we have to guard it
//TODO: Evaluate alternatives to importing the CLI. Generate our own client? Use a dynamic client?
// TODO: Evaluate alternatives to importing the CLI. Generate our own client? Use a dynamic client?
if flag.Lookup("kubeconfig") == nil {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
}
Expand All @@ -166,7 +163,7 @@ func main() {
flag.Var(&nodeContainerdRegistryMirrors, "node-containerd-registry-mirrors", "Configure registry mirrors endpoints. Can be used multiple times to specify multiple mirrors")
flag.StringVar(&caBundleFile, "ca-bundle", "", "path to a file containing all PEM-encoded CA certificates (will be used instead of the host's certificates if set)")
flag.BoolVar(&nodeCSRApprover, "node-csr-approver", true, "Enable NodeCSRApprover controller to automatically approve node serving certificate requests")
flag.StringVar(&podCIDRs, "pod-cidr", "172.25.0.0/16", "Comma separated network ranges from which POD networks are allocated. Example: 172.25.0.0/16,fd00::/104")
flag.StringVar(&podCIDR, "pod-cidr", "172.25.0.0/16", "WARNING: flag is unused, kept only for backwards compatibility")
flag.StringVar(&nodePortRange, "node-port-range", "30000-32767", "A port range to reserve for services with NodePort visibility")
flag.StringVar(&nodeRegistryCredentialsSecret, "node-registry-credentials-secret", "", "A Secret object reference, that containt auth info for image registry in namespace/secret-name form, example: kube-system/registry-credentials. See doc at https://github.com/kubermaric/machine-controller/blob/master/docs/registry-authentication.md")
flag.BoolVar(&useOSM, "use-osm", false, "use osm controller for node bootstrap")
Expand Down Expand Up @@ -266,7 +263,6 @@ func main() {
ContainerRuntime: containerRuntimeConfig,
},
useOSM: useOSM,
podCIDRs: strings.Split(podCIDRs, ","),
nodePortRange: nodePortRange,
}

Expand Down Expand Up @@ -402,7 +398,6 @@ func (bs *controllerBootstrap) Start(ctx context.Context) error {
bs.opt.skipEvictionAfter,
bs.opt.node,
bs.opt.useOSM,
bs.opt.podCIDRs,
bs.opt.nodePortRange,
); err != nil {
return fmt.Errorf("failed to add Machine controller to manager: %v", err)
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type UserDataRequest struct {
KubeletFeatureGates map[string]bool
KubeletConfigs map[string]string
ContainerRuntime containerruntime.Config
PodCIDRs []string
NodePortRange string
}

Expand Down
7 changes: 2 additions & 5 deletions pkg/cloudprovider/provider/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,8 @@ func getDefaultRootDevicePath(os providerconfigtypes.OperatingSystem) (string, e
return "", fmt.Errorf("no default root path found for %s operating system", os)
}

//gocyclo:ignore
func (p *provider) getConfig(provSpec clusterv1alpha1.ProviderSpec) (*Config, *providerconfigtypes.Config, *awstypes.RawConfig, error) {
if provSpec.Value == nil {
return nil, nil, nil, fmt.Errorf("machine.spec.providerconfig.value is nil")
}

pconfig, err := providerconfigtypes.GetConfig(provSpec)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -848,7 +845,7 @@ func (p *provider) Cleanup(machine *clusterv1alpha1.Machine, _ *cloudprovidertyp
return false, err
}

//(*Config, *providerconfigtypes.Config, *awstypes.RawConfig, error)
// (*Config, *providerconfigtypes.Config, *awstypes.RawConfig, error)
config, _, _, err := p.getConfig(machine.Spec.ProviderSpec)

if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions pkg/controller/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ type Reconciler struct {
satelliteSubscriptionManager rhsm.SatelliteSubscriptionManager

useOSM bool
podCIDRs []string
nodePortRange string
}

Expand Down Expand Up @@ -176,7 +175,6 @@ func Add(
skipEvictionAfter time.Duration,
nodeSettings NodeSettings,
useOSM bool,
podCIDRs []string,
nodePortRange string,
) error {
reconciler := &Reconciler{
Expand All @@ -195,7 +193,6 @@ func Add(
satelliteSubscriptionManager: rhsm.NewSatelliteSubscriptionManager(),

useOSM: useOSM,
podCIDRs: podCIDRs,
nodePortRange: nodePortRange,
}
m, err := userdatamanager.New()
Expand Down Expand Up @@ -426,7 +423,7 @@ func (r *Reconciler) reconcile(ctx context.Context, machine *clusterv1alpha1.Mac

node, err := r.getNodeByNodeRef(ctx, machine.Status.NodeRef)
if err != nil {
//In case we cannot find a node for the NodeRef we must remove the NodeRef & recreate an instance on the next sync
// In case we cannot find a node for the NodeRef we must remove the NodeRef & recreate an instance on the next sync
if kerrors.IsNotFound(err) {
klog.V(3).Infof("found invalid NodeRef on machine %s. Deleting reference...", machine.Name)
return nil, r.updateMachine(machine, func(m *clusterv1alpha1.Machine) {
Expand Down Expand Up @@ -803,7 +800,6 @@ func (r *Reconciler) ensureInstanceExistsForMachine(
NoProxy: r.nodeSettings.NoProxy,
HTTPProxy: r.nodeSettings.HTTPProxy,
ContainerRuntime: crRuntime,
PodCIDRs: r.podCIDRs,
NodePortRange: r.nodePortRange,
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/providerconfig/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ type NetworkConfig struct {
IPFamily util.IPFamily `json:"ipFamily,omitempty"`
}

func (n *NetworkConfig) IsStaticIPConfig() bool {
if n == nil {
return false
}
return n.CIDR != "" ||
n.Gateway != "" ||
len(n.DNS.Servers) != 0
}

func (n *NetworkConfig) GetIPFamily() util.IPFamily {
if n == nil {
return util.Unspecified
Expand Down
2 changes: 1 addition & 1 deletion pkg/userdata/amzn2/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Provider) UserData(req plugin.UserDataRequest) (string, error) {
req.CloudConfig = *pconfig.OverwriteCloudConfig
}

if pconfig.Network != nil {
if pconfig.Network.IsStaticIPConfig() {
return "", errors.New("static IP config is not supported with Amazon Linux 2")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/userdata/centos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Provider) UserData(req plugin.UserDataRequest) (string, error) {
req.CloudConfig = *pconfig.OverwriteCloudConfig
}

if pconfig.Network != nil {
if pconfig.Network.IsStaticIPConfig() {
return "", errors.New("static IP config is not supported with CentOS")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/userdata/rhel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Provider) UserData(req plugin.UserDataRequest) (string, error) {
req.CloudConfig = *pconfig.OverwriteCloudConfig
}

if pconfig.Network != nil {
if pconfig.Network.IsStaticIPConfig() {
return "", errors.New("static IP config is not supported with RHEL")
}

Expand Down
1 change: 0 additions & 1 deletion pkg/userdata/rhel/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func TestUserDataGeneration(t *testing.T) {
PauseImage: test.pauseImage,
KubeletFeatureGates: kubeletFeatureGates,
ContainerRuntime: containerRuntimeConfig,
PodCIDRs: []string{"172.25.0.0/16", "fd00::/104"},
}
s, err := provider.UserData(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/userdata/rockylinux/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Provider) UserData(req plugin.UserDataRequest) (string, error) {
req.CloudConfig = *pconfig.OverwriteCloudConfig
}

if pconfig.Network != nil {
if pconfig.Network.IsStaticIPConfig() {
return "", errors.New("static IP config is not supported with RockyLinux")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/userdata/sles/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (p Provider) UserData(req plugin.UserDataRequest) (string, error) {
req.CloudConfig = *pconfig.OverwriteCloudConfig
}

if pconfig.Network != nil {
if pconfig.Network.IsStaticIPConfig() {
return "", errors.New("static IP config is not supported with SLES")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/userdata/ubuntu/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Provider) UserData(req plugin.UserDataRequest) (string, error) {
req.CloudConfig = *pconfig.OverwriteCloudConfig
}

if pconfig.Network != nil {
if pconfig.Network.IsStaticIPConfig() {
return "", errors.New("static IP config is not supported with Ubuntu")
}

Expand Down

0 comments on commit 99a8a3f

Please sign in to comment.