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

AutoHEP Kube-Controller enable custom hostendpoint templates #9901

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions api/pkg/apis/projectcalico/v3/kubecontrollersconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ type NodeControllerConfig struct {
type AutoHostEndpointConfig struct {
// AutoCreate enables automatic creation of host endpoints for every node. [Default: Disabled]
AutoCreate string `json:"autoCreate,omitempty" validate:"omitempty,oneof=Enabled Disabled"`

CreateDefaultHostEndpoint DefaultHostEndpointMode `json:"createDefaultHostEndpoint,omitempty" validate:"omitempty,createDefaultHostEndpoint"`

// Templates contains definition for creating AutoHostEndpoints
Templates []Template `json:"templates,omitempty" validate:"omitempty"`
}

type DefaultHostEndpointMode string

const (
DefaultHostEndpointsEnabled DefaultHostEndpointMode = "Enabled"
DefaultHostEndpointsDisabled DefaultHostEndpointMode = "Disabled"
)

type Template struct {
// Name is appended to the end of the generated AutoHostEndpoint name
GenerateName string `json:"generateName,omitempty" validate:"omitempty,name"`

// InterfaceCIDRs contains a list of CIRDs used for matching nodeIPs to the AutoHostEndpoint
InterfaceCIDRs []string `json:"interfaceCIDRs,omitempty" validate:"cidrs"`

// Labels adds the specified labels to the generated AutoHostEndpoint, labels from node with the same name will be overwritten by values from the template label
Labels map[string]string `json:"labels,omitempty" validate:"omitempty,labels"`

// NodeSelector allows the AutoHostEndpoint to be created only for specific nodes
NodeSelector string `json:"nodeSelector,omitempty" validate:"omitempty,selector"`
}

// PolicyControllerConfig configures the network policy controller, which syncs Kubernetes policies
Expand Down
37 changes: 36 additions & 1 deletion api/pkg/apis/projectcalico/v3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions api/pkg/openapi/generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ rules:
- create
- update
- delete
- watch
# Needs access to update clusterinformations.
- apiGroups: ["crd.projectcalico.org"]
resources:
Expand Down
53 changes: 33 additions & 20 deletions kube-controllers/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ var _ = Describe("Config", func() {

rc := runCfg.Controllers
Expect(rc.Node).To(Equal(&config.NodeControllerConfig{
SyncLabels: true,
AutoHostEndpoints: false,
DeleteNodes: true,
LeakGracePeriod: &v1.Duration{Duration: 15 * time.Minute},
SyncLabels: true,
AutoHostEndpointConfig: &config.AutoHostEndpointConfig{
AutoCreate: false,
CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled,
Templates: nil,
},
DeleteNodes: true,
LeakGracePeriod: &v1.Duration{Duration: 15 * time.Minute},
}))
Expect(rc.Policy).To(Equal(&config.GenericControllerConfig{
ReconcilerPeriod: time.Minute * 5,
Expand Down Expand Up @@ -159,7 +163,7 @@ var _ = Describe("Config", func() {
Expect(c.Node).To(Equal(&v3.NodeControllerConfig{
ReconcilerPeriod: nil,
SyncLabels: v3.Enabled,
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Disabled},
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Disabled, CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled},
LeakGracePeriod: &v1.Duration{Duration: 15 * time.Minute},
}))
Expect(c.Policy).To(Equal(&v3.PolicyControllerConfig{
Expand Down Expand Up @@ -194,7 +198,7 @@ var _ = Describe("Config", func() {
Node: &v3.NodeControllerConfig{
ReconcilerPeriod: nil,
SyncLabels: v3.Disabled,
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled},
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled, CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled},
LeakGracePeriod: &v1.Duration{Duration: 20 * time.Minute},
},
Policy: &v3.PolicyControllerConfig{
Expand Down Expand Up @@ -227,10 +231,13 @@ var _ = Describe("Config", func() {

rc := runCfg.Controllers
Expect(rc.Node).To(Equal(&config.NodeControllerConfig{
SyncLabels: false,
AutoHostEndpoints: true,
DeleteNodes: true,
LeakGracePeriod: &v1.Duration{Duration: 20 * time.Minute},
SyncLabels: false,
AutoHostEndpointConfig: &config.AutoHostEndpointConfig{
AutoCreate: true,
CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled,
},
DeleteNodes: true,
LeakGracePeriod: &v1.Duration{Duration: 20 * time.Minute},
}))
Expect(rc.Policy).To(Equal(&config.GenericControllerConfig{
ReconcilerPeriod: time.Second * 30,
Expand Down Expand Up @@ -453,10 +460,10 @@ var _ = Describe("Config", func() {

rc := runCfg.Controllers
Expect(rc.Node).To(Equal(&config.NodeControllerConfig{
SyncLabels: false,
AutoHostEndpoints: true,
DeleteNodes: true,
LeakGracePeriod: &v1.Duration{Duration: 15 * time.Minute},
SyncLabels: false,
AutoHostEndpointConfig: &config.AutoHostEndpointConfig{AutoCreate: true, CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled},
DeleteNodes: true,
LeakGracePeriod: &v1.Duration{Duration: 15 * time.Minute},
}))
Expect(rc.Policy).To(Equal(&config.GenericControllerConfig{
ReconcilerPeriod: time.Second * 105,
Expand Down Expand Up @@ -488,7 +495,7 @@ var _ = Describe("Config", func() {
Expect(c.Node).To(Equal(&v3.NodeControllerConfig{
ReconcilerPeriod: nil,
SyncLabels: v3.Disabled,
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled},
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled, CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled},
LeakGracePeriod: &v1.Duration{Duration: 15 * time.Minute},
}))
Expect(c.Policy).To(Equal(&v3.PolicyControllerConfig{
Expand Down Expand Up @@ -517,7 +524,10 @@ var _ = Describe("Config", func() {
Node: &v3.NodeControllerConfig{
ReconcilerPeriod: nil,
SyncLabels: v3.Disabled,
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled},
HostEndpoint: &v3.AutoHostEndpointConfig{
AutoCreate: v3.Enabled,
CreateDefaultHostEndpoint: v3.DefaultHostEndpointsDisabled,
},
},
Policy: &v3.PolicyControllerConfig{
ReconcilerPeriod: &v1.Duration{Duration: time.Second * 30}},
Expand Down Expand Up @@ -546,9 +556,12 @@ var _ = Describe("Config", func() {

rc := runCfg.Controllers
Expect(rc.Node).To(Equal(&config.NodeControllerConfig{
SyncLabels: false,
AutoHostEndpoints: true,
DeleteNodes: true,
SyncLabels: false,
AutoHostEndpointConfig: &config.AutoHostEndpointConfig{
AutoCreate: true,
CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled,
},
DeleteNodes: true,
}))
Expect(rc.Policy).To(Equal(&config.GenericControllerConfig{
ReconcilerPeriod: time.Second * 105,
Expand Down Expand Up @@ -580,7 +593,7 @@ var _ = Describe("Config", func() {
Expect(c.Node).To(Equal(&v3.NodeControllerConfig{
ReconcilerPeriod: nil,
SyncLabels: v3.Disabled,
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled},
HostEndpoint: &v3.AutoHostEndpointConfig{AutoCreate: v3.Enabled, CreateDefaultHostEndpoint: v3.DefaultHostEndpointsEnabled},
}))
Expect(c.Policy).To(Equal(&v3.PolicyControllerConfig{
ReconcilerPeriod: &v1.Duration{Duration: time.Second * 105}}))
Expand Down
Loading