Skip to content

Commit 694c17e

Browse files
committed
move apiserver component from calico-apiserver ns to calico-system for OSS
1 parent 6190905 commit 694c17e

File tree

8 files changed

+107
-140
lines changed

8 files changed

+107
-140
lines changed

pkg/controller/apiserver/apiserver_controller.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import (
5252
"github.com/tigera/operator/pkg/render"
5353
rcertificatemanagement "github.com/tigera/operator/pkg/render/certificatemanagement"
5454
"github.com/tigera/operator/pkg/render/common/authentication"
55-
rmeta "github.com/tigera/operator/pkg/render/common/meta"
5655
"github.com/tigera/operator/pkg/render/common/networkpolicy"
5756
"github.com/tigera/operator/pkg/render/monitor"
5857
"github.com/tigera/operator/pkg/tls/certificatemanagement"
@@ -78,7 +77,7 @@ func Add(mgr manager.Manager, opts options.AddOptions) error {
7877
go utils.WaitToAddTierWatch(networkpolicy.TigeraComponentTierName, c, opts.K8sClientset, log, r.tierWatchReady)
7978

8079
go utils.WaitToAddNetworkPolicyWatches(c, opts.K8sClientset, log, []types.NamespacedName{
81-
{Name: render.APIServerPolicyName, Namespace: rmeta.APIServerNamespace(operatorv1.TigeraSecureEnterprise)},
80+
{Name: render.APIServerPolicyName, Namespace: render.APIServerNamespace},
8281
})
8382
}
8483

@@ -139,7 +138,7 @@ func add(c ctrlruntime.Controller, r *ReconcileAPIServer) error {
139138
return fmt.Errorf("apiserver-controller failed to watch primary resource: %v", err)
140139
}
141140

142-
for _, namespace := range []string{common.OperatorNamespace(), rmeta.APIServerNamespace(operatorv1.TigeraSecureEnterprise)} {
141+
for _, namespace := range []string{common.OperatorNamespace(), render.APIServerNamespace} {
143142
for _, secretName := range []string{render.VoltronTunnelSecretName, render.ManagerTLSSecretName} {
144143
if err = utils.AddSecretsWatch(c, secretName, namespace); err != nil {
145144
return fmt.Errorf("apiserver-controller failed to watch the Secret resource: %v", err)
@@ -156,10 +155,10 @@ func add(c ctrlruntime.Controller, r *ReconcileAPIServer) error {
156155
}
157156

158157
// Watch for the namespace(s) managed by this controller.
159-
if err = c.WatchObject(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: rmeta.APIServerNamespace(operatorv1.Calico)}}, &handler.EnqueueRequestForObject{}); err != nil {
158+
if err = c.WatchObject(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: render.APIServerNamespace}}, &handler.EnqueueRequestForObject{}); err != nil {
160159
return fmt.Errorf("apiserver-controller failed to watch resource: %w", err)
161160
}
162-
if err = c.WatchObject(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: rmeta.APIServerNamespace(operatorv1.TigeraSecureEnterprise)}}, &handler.EnqueueRequestForObject{}); err != nil {
161+
if err = c.WatchObject(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: render.APIServerNamespace}}, &handler.EnqueueRequestForObject{}); err != nil {
163162
return fmt.Errorf("apiserver-controller failed to watch resource: %w", err)
164163
}
165164

@@ -261,7 +260,6 @@ func (r *ReconcileAPIServer) Reconcile(ctx context.Context, request reconcile.Re
261260
r.status.SetDegraded(operatorv1.ResourceNotReady, "Waiting for Installation Variant to be set", nil, reqLogger)
262261
return reconcile.Result{}, nil
263262
}
264-
ns := rmeta.APIServerNamespace(installationSpec.Variant)
265263

266264
certificateManager, err := certificatemanager.Create(r.client, installationSpec, r.clusterDomain, common.OperatorNamespace())
267265
if err != nil {
@@ -271,13 +269,13 @@ func (r *ReconcileAPIServer) Reconcile(ctx context.Context, request reconcile.Re
271269

272270
// We need separate certificates for OSS vs Enterprise.
273271
secretName := render.ProjectCalicoAPIServerTLSSecretName(installationSpec.Variant)
274-
tlsSecret, err := certificateManager.GetOrCreateKeyPair(r.client, secretName, common.OperatorNamespace(), dns.GetServiceDNSNames(render.ProjectCalicoAPIServerServiceName(installationSpec.Variant), rmeta.APIServerNamespace(installationSpec.Variant), r.clusterDomain))
272+
tlsSecret, err := certificateManager.GetOrCreateKeyPair(r.client, secretName, common.OperatorNamespace(), dns.GetServiceDNSNames(render.ProjectCalicoAPIServerServiceName(installationSpec.Variant), render.APIServerNamespace, r.clusterDomain))
275273
if err != nil {
276274
r.status.SetDegraded(operatorv1.ResourceCreateError, "Unable to get or create tls key pair", err, reqLogger)
277275
return reconcile.Result{}, err
278276
}
279277

280-
certificateManager.AddToStatusManager(r.status, ns)
278+
certificateManager.AddToStatusManager(r.status, render.APIServerNamespace)
281279

282280
pullSecrets, err := utils.GetNetworkingPullSecrets(installationSpec, r.client)
283281
if err != nil {
@@ -439,7 +437,7 @@ func (r *ReconcileAPIServer) Reconcile(ctx context.Context, request reconcile.Re
439437
MultiTenant: r.multiTenant,
440438
KeyValidatorConfig: keyValidatorConfig,
441439
KubernetesVersion: r.kubernetesVersion,
442-
CanCleanupOlderResources: r.canCleanupLegacyNamespace(ctx, reqLogger),
440+
CanCleanupOlderResources: r.canCleanupLegacyNamespace(ctx, installationSpec.Variant, reqLogger),
443441
}
444442

445443
var components []render.Component
@@ -460,7 +458,7 @@ func (r *ReconcileAPIServer) Reconcile(ctx context.Context, request reconcile.Re
460458
components = append(components,
461459
component,
462460
rcertificatemanagement.CertificateManagement(&rcertificatemanagement.Config{
463-
Namespace: rmeta.APIServerNamespace(installationSpec.Variant),
461+
Namespace: render.APIServerNamespace,
464462
ServiceAccounts: []string{render.APIServerServiceAccountName(installationSpec.Variant)},
465463
KeyPairOptions: []rcertificatemanagement.KeyPairOption{
466464
rcertificatemanagement.NewKeyPairOption(tlsSecret, true, true),
@@ -515,11 +513,7 @@ func validateAPIServerResource(instance *operatorv1.APIServer) error {
515513
// prior to the CNI plugin being removed.
516514
func (r *ReconcileAPIServer) maintainFinalizer(ctx context.Context, apiserver client.Object) error {
517515
// These objects require graceful termination before the CNI plugin is torn down.
518-
_, spec, err := utils.GetInstallation(context.Background(), r.client)
519-
if err != nil {
520-
return err
521-
}
522-
apiServerNamespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: rmeta.APIServerNamespace(spec.Variant)}}
516+
apiServerNamespace := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: render.APIServerNamespace}}
523517
return utils.MaintainInstallationFinalizer(ctx, r.client, apiserver, render.APIServerFinalizer, apiServerNamespace)
524518
}
525519

@@ -529,12 +523,16 @@ func (r *ReconcileAPIServer) maintainFinalizer(ctx context.Context, apiserver cl
529523
// - The new API server deployment in "calico-system" exists and is available.
530524
// - The old API server deployment in "tigera-system" is either removed or inactive.
531525
// - Both the APIServer custom resource and the TigeraStatus for 'apiserver' are in the Ready state
532-
func (r *ReconcileAPIServer) canCleanupLegacyNamespace(ctx context.Context, logger logr.Logger) bool {
533-
const (
534-
newNamespace = "calico-system"
535-
oldNamespace = "tigera-system"
536-
deploymentName = "tigera-apiserver"
537-
)
526+
func (r *ReconcileAPIServer) canCleanupLegacyNamespace(ctx context.Context, variant operatorv1.ProductVariant, logger logr.Logger) bool {
527+
528+
newNamespace := "calico-system"
529+
oldNamespace := "tigera-system"
530+
deploymentName := "tigera-apiserver"
531+
532+
if variant == operatorv1.Calico {
533+
oldNamespace = "calico-apiserver"
534+
deploymentName = "calico-apiserver"
535+
}
538536

539537
// Fetch the new API server deployment in calico-system
540538
newDeploy := &appsv1.Deployment{}

pkg/controller/apiserver/apiserver_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ var _ = Describe("apiserver controller tests", func() {
836836
}
837837
_, err = r.Reconcile(ctx, reconcile.Request{})
838838
Expect(err).ShouldNot(HaveOccurred())
839-
canCleanedUp := r.canCleanupLegacyNamespace(ctx, logf.Log.WithName("test"))
839+
canCleanedUp := r.canCleanupLegacyNamespace(ctx, installation.Spec.Variant, logf.Log.WithName("test"))
840840
Expect(canCleanedUp).To(BeTrue())
841841
})
842842

@@ -856,7 +856,7 @@ var _ = Describe("apiserver controller tests", func() {
856856
}
857857
_, err = r.Reconcile(ctx, reconcile.Request{})
858858
Expect(err).ShouldNot(HaveOccurred())
859-
canCleanedUp := r.canCleanupLegacyNamespace(ctx, logf.Log.WithName("test"))
859+
canCleanedUp := r.canCleanupLegacyNamespace(ctx, installation.Spec.Variant, logf.Log.WithName("test"))
860860
Expect(canCleanedUp).To(BeFalse())
861861
})
862862

@@ -882,7 +882,7 @@ var _ = Describe("apiserver controller tests", func() {
882882
}
883883
_, err = r.Reconcile(ctx, reconcile.Request{})
884884
Expect(err).ShouldNot(HaveOccurred())
885-
canCleanedUp := r.canCleanupLegacyNamespace(ctx, logf.Log.WithName("test"))
885+
canCleanedUp := r.canCleanupLegacyNamespace(ctx, installation.Spec.Variant, logf.Log.WithName("test"))
886886
Expect(canCleanedUp).To(BeFalse())
887887
})
888888

@@ -916,7 +916,7 @@ var _ = Describe("apiserver controller tests", func() {
916916
}
917917
_, err = r.Reconcile(ctx, reconcile.Request{})
918918
Expect(err).ShouldNot(HaveOccurred())
919-
canCleanedUp := r.canCleanupLegacyNamespace(ctx, logf.Log.WithName("test"))
919+
canCleanedUp := r.canCleanupLegacyNamespace(ctx, installation.Spec.Variant, logf.Log.WithName("test"))
920920
Expect(canCleanedUp).To(BeFalse())
921921
})
922922
})

pkg/controller/tiers/tiers_controller.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"github.com/tigera/operator/pkg/controller/utils"
4343
"github.com/tigera/operator/pkg/ctrlruntime"
4444
"github.com/tigera/operator/pkg/render"
45-
rmeta "github.com/tigera/operator/pkg/render/common/meta"
4645
"github.com/tigera/operator/pkg/render/common/networkpolicy"
4746
"github.com/tigera/operator/pkg/render/logstorage/eck"
4847
"github.com/tigera/operator/pkg/render/logstorage/kibana"
@@ -194,7 +193,6 @@ func (r *ReconcileTiers) prepareTiersConfig(ctx context.Context, reqLogger logr.
194193
render.PacketCaptureNamespace,
195194
render.PolicyRecommendationNamespace,
196195
common.TigeraPrometheusNamespace,
197-
rmeta.APIServerNamespace(operatorv1.TigeraSecureEnterprise),
198196
"tigera-skraper",
199197
}
200198
if r.multiTenant {

0 commit comments

Comments
 (0)