Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions charts/calico/templates/calico-node-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ rules:
resources:
- ippools
- felixconfigurations
- bgpconfigurations
- clusterinformations
verbs:
- create
Expand Down
40 changes: 18 additions & 22 deletions e2e/pkg/tests/bgp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,41 @@ import (
v3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
"github.com/projectcalico/api/pkg/lib/numorstring"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/projectcalico/calico/libcalico-go/lib/backend/k8s/resources"
)

// ensureInitialBGPConfig checks for an existing BGPConfiguration resource and ensures that full mesh BGP is enabled.
// ensureInitialBGPConfig updates the default BGPConfiguration to ensures that full mesh BGP is enabled.
// It returns a cleanup function to restore the original state after the test.
func ensureInitialBGPConfig(cli ctrlclient.Client) func() {
// Ensure full mesh BGP is functioning before each test.
initialConfig := &v3.BGPConfiguration{}
err := cli.Get(context.Background(), ctrlclient.ObjectKey{Name: "default"}, initialConfig)
if errors.IsNotFound(err) {
// Not found - simply create a new one, enabling full mesh (the default behavior). Ideally, our product code
// would do this automatically, but we do it here until it does.
ginkgo.By("Creating default BGPConfiguration suitable for tests")
err = cli.Create(context.Background(), &v3.BGPConfiguration{
ObjectMeta: metav1.ObjectMeta{Name: "default"},
Spec: v3.BGPConfigurationSpec{
NodeToNodeMeshEnabled: ptr.To(true),
},
})
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Error creating BGPConfiguration resource")

return func() {
ginkgo.By("Deleting BGPConfiguration created for tests")
err := cli.Delete(context.Background(), &v3.BGPConfiguration{ObjectMeta: metav1.ObjectMeta{Name: "default"}})
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Error deleting BGPConfiguration resource")
}
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Error querying default BGPConfiguration resource")

updated := false
updatedConfig := *initialConfig
if initialConfig.Spec.NodeToNodeMeshEnabled == nil || !*initialConfig.Spec.NodeToNodeMeshEnabled {
updatedConfig.Spec.NodeToNodeMeshEnabled = ptr.To(true)
err = cli.Update(context.Background(), &updatedConfig)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Error updating BGPConfiguration resource to enable mesh")
updated = true

err = cli.Get(context.Background(), ctrlclient.ObjectKey{Name: "default"}, &updatedConfig)
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Error querying default BGPConfiguration resource")
}

ginkgo.By("Ensuring full mesh BGP is enabled in existing BGPConfiguration")
ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Error querying BGPConfiguration resource")
ExpectWithOffset(1, initialConfig.Spec.NodeToNodeMeshEnabled).NotTo(BeNil(), "nodeToNodeMeshEnabled is not configured in BGPConfiguration")
ExpectWithOffset(1, *initialConfig.Spec.NodeToNodeMeshEnabled).To(BeTrue(), "nodeToNodeMeshEnabled is not enabled in BGPConfiguration")
ExpectWithOffset(1, updatedConfig.Spec.NodeToNodeMeshEnabled).NotTo(BeNil(), "nodeToNodeMeshEnabled is not configured in BGPConfiguration")
ExpectWithOffset(1, *updatedConfig.Spec.NodeToNodeMeshEnabled).To(BeTrue(), "nodeToNodeMeshEnabled is not enabled in BGPConfiguration")

return func() {
if !updated {
return
}
ginkgo.By("Restoring initial BGPConfiguration")
// Query the resource again to get the latest resource version.
currentConfig := &v3.BGPConfiguration{}
Expand Down
4 changes: 2 additions & 2 deletions hack/test/kind/deploy_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ if [[ "$CLUSTER_ROUTING" == "FELIX" ]]; then
echo "Patching FelixConfiguration to configure Felix program cluster routes"
${kubectl} patch felixconfiguration default --type='merge' -p '{"spec":{"programClusterRoutes":"Enabled"}}'

echo "Apply BGPConfiguration to configure BIRD to not program cluster routes"
${kubectl} apply -f ${INFRA_DIR}/bgpconfig.yaml
echo "Patching BGPConfiguration to configure BIRD to not program cluster routes"
${kubectl} patch bgpconfiguration default --type='merge' -p '{"spec":{"programClusterRoutes":"Disabled"}}'
fi

echo "Install MetalLB controller for allocating LoadBalancer IPs"
Expand Down
7 changes: 0 additions & 7 deletions hack/test/kind/infra/bgpconfig.yaml

This file was deleted.

1 change: 1 addition & 0 deletions manifests/calico-bpf.yaml

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

1 change: 1 addition & 0 deletions manifests/calico-policy-only.yaml

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

1 change: 1 addition & 0 deletions manifests/calico-typha.yaml

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

1 change: 1 addition & 0 deletions manifests/calico-vxlan.yaml

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

1 change: 1 addition & 0 deletions manifests/calico.yaml

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

1 change: 1 addition & 0 deletions manifests/canal.yaml

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

1 change: 1 addition & 0 deletions manifests/flannel-migration/calico.yaml

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

43 changes: 39 additions & 4 deletions node/pkg/lifecycle/startup/startup.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2025 Tigera, Inc. All rights reserved.
// Copyright (c) 2016-2026 Tigera, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,6 +75,7 @@ var (
defaultLogSeverity = "Info"
globalFelixConfigName = "default"
felixNodeConfigNamePrefix = "node."
globalBGPConfigName = "default"
)

type runConf struct {
Expand Down Expand Up @@ -1211,9 +1212,16 @@ func checkConflictingNodes(ctx context.Context, client client.Interface, node *i
return
}

// ensureDefaultConfig ensures all of the required default settings are
// configured.
func ensureDefaultConfig(ctx context.Context, cfg *apiconfig.CalicoAPIConfig, c client.Interface, node *internalapi.Node, osType string, kubeadmConfig, rancherState *v1.ConfigMap) error {
// ensureDefaultConfig ensures all of the required default settings are configured.
func ensureDefaultConfig(
ctx context.Context,
cfg *apiconfig.CalicoAPIConfig,
c client.Interface,
node *internalapi.Node,
osType string,
kubeadmConfig,
rancherState *v1.ConfigMap,
) error {
// Ensure the ClusterInformation is populated.
// Get the ClusterType from ENV var. This is set from the manifest.
clusterType := os.Getenv("CLUSTER_TYPE")
Expand Down Expand Up @@ -1347,6 +1355,33 @@ func ensureDefaultConfig(ctx context.Context, cfg *apiconfig.CalicoAPIConfig, c
}
}

return ensureDefaultBGPConfigExists(ctx, c)
Comment thread
mazdakn marked this conversation as resolved.
}

func ensureDefaultBGPConfigExists(ctx context.Context, c client.Interface) error {
_, err := c.BGPConfigurations().Get(ctx, globalBGPConfigName, options.GetOptions{})
if err == nil {
log.Debug("Default BGPConfig exists.")
return nil
}

_, ok := err.(cerrors.ErrorResourceDoesNotExist)
if !ok {
log.WithError(err).WithField("BGPConfig", globalBGPConfigName).Errorf("Error getting global BGPConfig.")
return err
}

newBGPConf := api.NewBGPConfiguration()
newBGPConf.Name = globalBGPConfigName
Comment thread
mazdakn marked this conversation as resolved.
_, err = c.BGPConfigurations().Create(ctx, newBGPConf, options.SetOptions{})
Comment thread
mazdakn marked this conversation as resolved.
if err != nil {
if conflict, exists := err.(cerrors.ErrorResourceAlreadyExists); exists {
log.Infof("Ignoring conflict when setting value %s", conflict.Identifier)
} else {
log.WithError(err).WithField("BGPConfig", newBGPConf).Errorf("Error creating default BGPConfiguration.")
return err
}
}
return nil
}

Expand Down
Loading