mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
Do all the trivial conversion (#62945)
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -125,15 +126,15 @@ func (g *appV3TestingPrimitives) CompareTeleportAndKubernetesResource(tResource
|
||||
|
||||
func TestTeleportAppV3Creation(t *testing.T) {
|
||||
test := &appV3TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Application, *resourcesv1.TeleportAppV3](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Application, *resourcesv1.TeleportAppV3](t, resources.NewAppV3Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportAppV3DeletionDrift(t *testing.T) {
|
||||
test := &appV3TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Application, *resourcesv1.TeleportAppV3](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Application, *resourcesv1.TeleportAppV3](t, resources.NewAppV3Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportAppV3Update(t *testing.T) {
|
||||
test := &appV3TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Application, *resourcesv1.TeleportAppV3](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Application, *resourcesv1.TeleportAppV3](t, resources.NewAppV3Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types/autoupdate"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -168,15 +169,30 @@ func (g *autoUpdateConfigTestingPrimitives) CompareTeleportAndKubernetesResource
|
||||
|
||||
func TestAutoUpdateConfigCreation(t *testing.T) {
|
||||
test := &autoUpdateConfigTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[*autoupdatev1pb.AutoUpdateConfig, *resourcesv1.TeleportAutoupdateConfigV1](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[*autoupdatev1pb.AutoUpdateConfig, *resourcesv1.TeleportAutoupdateConfigV1](
|
||||
t,
|
||||
resources.NewAutoUpdateConfigV1Reconciler,
|
||||
test,
|
||||
testlib.WithResourceName(types.MetaNameAutoUpdateConfig),
|
||||
)
|
||||
}
|
||||
|
||||
func TestAutoUpdateConfigDeletionDrift(t *testing.T) {
|
||||
test := &autoUpdateConfigTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[*autoupdatev1pb.AutoUpdateConfig, *resourcesv1.TeleportAutoupdateConfigV1](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[*autoupdatev1pb.AutoUpdateConfig, *resourcesv1.TeleportAutoupdateConfigV1](
|
||||
t,
|
||||
resources.NewAutoUpdateConfigV1Reconciler,
|
||||
test,
|
||||
testlib.WithResourceName(types.MetaNameAutoUpdateConfig),
|
||||
)
|
||||
}
|
||||
|
||||
func TestAutoUpdateConfigUpdate(t *testing.T) {
|
||||
test := &autoUpdateConfigTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[*autoupdatev1pb.AutoUpdateConfig, *resourcesv1.TeleportAutoupdateConfigV1](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[*autoupdatev1pb.AutoUpdateConfig, *resourcesv1.TeleportAutoupdateConfigV1](
|
||||
t,
|
||||
resources.NewAutoUpdateConfigV1Reconciler,
|
||||
test,
|
||||
testlib.WithResourceName(types.MetaNameAutoUpdateConfig),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types/autoupdate"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -148,15 +149,30 @@ func (g *autoUpdateVersionTestingPrimitives) CompareTeleportAndKubernetesResourc
|
||||
|
||||
func TestAutoUpdateVersionCreation(t *testing.T) {
|
||||
test := &autoUpdateVersionTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[*autoupdatev1pb.AutoUpdateVersion, *resourcesv1.TeleportAutoupdateVersionV1](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[*autoupdatev1pb.AutoUpdateVersion, *resourcesv1.TeleportAutoupdateVersionV1](
|
||||
t,
|
||||
resources.NewAutoUpdateVersionV1Reconciler,
|
||||
test,
|
||||
testlib.WithResourceName("autoupdate-version"),
|
||||
)
|
||||
}
|
||||
|
||||
func TestAutoUpdateVersionDeletionDrift(t *testing.T) {
|
||||
test := &autoUpdateVersionTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[*autoupdatev1pb.AutoUpdateVersion, *resourcesv1.TeleportAutoupdateVersionV1](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[*autoupdatev1pb.AutoUpdateVersion, *resourcesv1.TeleportAutoupdateVersionV1](
|
||||
t,
|
||||
resources.NewAutoUpdateVersionV1Reconciler,
|
||||
test,
|
||||
testlib.WithResourceName("autoupdate-version"),
|
||||
)
|
||||
}
|
||||
|
||||
func TestAutoUpdateVersionUpdate(t *testing.T) {
|
||||
test := &autoUpdateVersionTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[*autoupdatev1pb.AutoUpdateVersion, *resourcesv1.TeleportAutoupdateVersionV1](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[*autoupdatev1pb.AutoUpdateVersion, *resourcesv1.TeleportAutoupdateVersionV1](
|
||||
t,
|
||||
resources.NewAutoUpdateVersionV1Reconciler,
|
||||
test,
|
||||
testlib.WithResourceName("autoupdate-version"),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
"github.com/gravitational/teleport/lib/defaults"
|
||||
)
|
||||
@@ -164,15 +165,15 @@ func (g *botTestingPrimitives) CompareTeleportAndKubernetesResource(
|
||||
|
||||
func TestBotCreation(t *testing.T) {
|
||||
test := &botTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[*machineidv1.Bot, *resourcesv1.TeleportBotV1](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[*machineidv1.Bot, *resourcesv1.TeleportBotV1](t, resources.NewBotV1Reconciler, test)
|
||||
}
|
||||
|
||||
func TestBotDeletionDrift(t *testing.T) {
|
||||
test := &botTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[*machineidv1.Bot, *resourcesv1.TeleportBotV1](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[*machineidv1.Bot, *resourcesv1.TeleportBotV1](t, resources.NewBotV1Reconciler, test)
|
||||
}
|
||||
|
||||
func TestBotUpdate(t *testing.T) {
|
||||
test := &botTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[*machineidv1.Bot, *resourcesv1.TeleportBotV1](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[*machineidv1.Bot, *resourcesv1.TeleportBotV1](t, resources.NewBotV1Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -118,15 +119,15 @@ func (g *databaseV3TestingPrimitives) CompareTeleportAndKubernetesResource(tReso
|
||||
|
||||
func TestTeleportDatabaseV3Creation(t *testing.T) {
|
||||
test := &databaseV3TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Database, *resourcesv1.TeleportDatabaseV3](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Database, *resourcesv1.TeleportDatabaseV3](t, resources.NewDatabaseV3Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportDatabaseV3DeletionDrift(t *testing.T) {
|
||||
test := &databaseV3TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Database, *resourcesv1.TeleportDatabaseV3](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Database, *resourcesv1.TeleportDatabaseV3](t, resources.NewDatabaseV3Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportDatabaseV3Update(t *testing.T) {
|
||||
test := &databaseV3TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Database, *resourcesv1.TeleportDatabaseV3](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Database, *resourcesv1.TeleportDatabaseV3](t, resources.NewDatabaseV3Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -27,11 +27,14 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
apimachinerytypes "k8s.io/apimachinery/pkg/types"
|
||||
kclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv3 "github.com/gravitational/teleport/integrations/operator/apis/resources/v3"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/secretlookup"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
@@ -127,22 +130,22 @@ func (g *githubTestingPrimitives) CompareTeleportAndKubernetesResource(tResource
|
||||
|
||||
func TestGithubConnectorCreation(t *testing.T) {
|
||||
test := &githubTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.GithubConnector, *resourcesv3.TeleportGithubConnector](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.GithubConnector, *resourcesv3.TeleportGithubConnector](t, resources.NewGithubConnectorReconciler, test)
|
||||
}
|
||||
|
||||
func TestGithubConnectorDeletionDrift(t *testing.T) {
|
||||
test := &githubTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.GithubConnector, *resourcesv3.TeleportGithubConnector](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.GithubConnector, *resourcesv3.TeleportGithubConnector](t, resources.NewGithubConnectorReconciler, test)
|
||||
}
|
||||
|
||||
func TestGithubConnectorUpdate(t *testing.T) {
|
||||
test := &githubTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.GithubConnector, *resourcesv3.TeleportGithubConnector](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.GithubConnector, *resourcesv3.TeleportGithubConnector](t, resources.NewGithubConnectorReconciler, test)
|
||||
}
|
||||
|
||||
func TestGithubConnectorSecretLookup(t *testing.T) {
|
||||
test := &githubTestingPrimitives{}
|
||||
setup := testlib.SetupTestEnv(t)
|
||||
setup := testlib.SetupFakeKubeTestEnv(t)
|
||||
test.Init(setup)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -159,6 +162,11 @@ func TestGithubConnectorSecretLookup(t *testing.T) {
|
||||
secretlookup.AllowLookupAnnotation: crName,
|
||||
},
|
||||
},
|
||||
// Real kube servers convert stringData into data.
|
||||
// The fake client does not, so we must use Data instead.
|
||||
Data: map[string][]byte{
|
||||
secretKey: []byte(secretValue),
|
||||
},
|
||||
StringData: map[string]string{
|
||||
secretKey: secretValue,
|
||||
},
|
||||
@@ -179,6 +187,24 @@ func TestGithubConnectorSecretLookup(t *testing.T) {
|
||||
|
||||
require.NoError(t, kubeClient.Create(ctx, github))
|
||||
|
||||
reconciler, err := resources.NewGithubConnectorReconciler(kubeClient, setup.TeleportClient)
|
||||
require.NoError(t, err)
|
||||
// Test execution: Kick off the reconciliation.
|
||||
req := reconcile.Request{
|
||||
NamespacedName: apimachinerytypes.NamespacedName{
|
||||
Namespace: setup.Namespace.Name,
|
||||
Name: crName,
|
||||
},
|
||||
}
|
||||
// First reconciliation should set the finalizer and exit.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
// Second reconciliation should create the Teleport resource.
|
||||
// In a real cluster we should receive the event of our own finalizer change
|
||||
// and this wakes us for a second round.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
|
||||
testlib.FastEventually(t, func() bool {
|
||||
gh, err := test.GetTeleportResource(ctx, crName)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,11 +28,14 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
apimachinerytypes "k8s.io/apimachinery/pkg/types"
|
||||
kclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv3 "github.com/gravitational/teleport/integrations/operator/apis/resources/v3"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/secretlookup"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
@@ -128,22 +131,22 @@ func (g *oidcTestingPrimitives) CompareTeleportAndKubernetesResource(tResource t
|
||||
|
||||
func TestOIDCConnectorCreation(t *testing.T) {
|
||||
test := &oidcTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.OIDCConnector, *resourcesv3.TeleportOIDCConnector](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.OIDCConnector, *resourcesv3.TeleportOIDCConnector](t, resources.NewOIDCConnectorReconciler, test)
|
||||
}
|
||||
|
||||
func TestOIDCConnectorDeletionDrift(t *testing.T) {
|
||||
test := &oidcTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.OIDCConnector, *resourcesv3.TeleportOIDCConnector](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.OIDCConnector, *resourcesv3.TeleportOIDCConnector](t, resources.NewOIDCConnectorReconciler, test)
|
||||
}
|
||||
|
||||
func TestOIDCConnectorUpdate(t *testing.T) {
|
||||
test := &oidcTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.OIDCConnector, *resourcesv3.TeleportOIDCConnector](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.OIDCConnector, *resourcesv3.TeleportOIDCConnector](t, resources.NewOIDCConnectorReconciler, test)
|
||||
}
|
||||
|
||||
func TestOIDCConnectorSecretLookup(t *testing.T) {
|
||||
test := &oidcTestingPrimitives{}
|
||||
setup := testlib.SetupTestEnv(t)
|
||||
setup := testlib.SetupFakeKubeTestEnv(t)
|
||||
test.Init(setup)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -160,8 +163,10 @@ func TestOIDCConnectorSecretLookup(t *testing.T) {
|
||||
secretlookup.AllowLookupAnnotation: crName,
|
||||
},
|
||||
},
|
||||
StringData: map[string]string{
|
||||
secretKey: secretValue,
|
||||
// Real kube servers convert stringData into data.
|
||||
// The fake client does not, so we must use Data instead.
|
||||
Data: map[string][]byte{
|
||||
secretKey: []byte(secretValue),
|
||||
},
|
||||
Type: v1.SecretTypeOpaque,
|
||||
}
|
||||
@@ -177,9 +182,26 @@ func TestOIDCConnectorSecretLookup(t *testing.T) {
|
||||
}
|
||||
|
||||
oidc.Spec.ClientSecret = "secret://" + secretName + "/" + secretKey
|
||||
|
||||
require.NoError(t, kubeClient.Create(ctx, oidc))
|
||||
|
||||
reconciler, err := resources.NewOIDCConnectorReconciler(kubeClient, setup.TeleportClient)
|
||||
require.NoError(t, err)
|
||||
// Test execution: Kick off the reconciliation.
|
||||
req := reconcile.Request{
|
||||
NamespacedName: apimachinerytypes.NamespacedName{
|
||||
Namespace: setup.Namespace.Name,
|
||||
Name: crName,
|
||||
},
|
||||
}
|
||||
// First reconciliation should set the finalizer and exit.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
// Second reconciliation should create the Teleport resource.
|
||||
// In a real cluster we should receive the event of our own finalizer change
|
||||
// and this wakes us for a second round.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
|
||||
testlib.FastEventually(t, func() bool {
|
||||
oidc, err := test.GetTeleportResource(ctx, crName)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -162,17 +163,17 @@ func (g *oktaImportRuleTestingPrimitives) CompareTeleportAndKubernetesResource(t
|
||||
func TestOktaImportRuleCreation(t *testing.T) {
|
||||
t.Skip("Skipping test since okta reconsider is not available in OSS")
|
||||
test := &oktaImportRuleTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.OktaImportRule, *resourcesv1.TeleportOktaImportRule](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.OktaImportRule, *resourcesv1.TeleportOktaImportRule](t, resources.NewOktaImportRuleReconciler, test)
|
||||
}
|
||||
|
||||
func TestOktaImportRuleDeletionDrift(t *testing.T) {
|
||||
t.Skip("Skipping test since okta reconsider is not available in OSS")
|
||||
test := &oktaImportRuleTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.OktaImportRule, *resourcesv1.TeleportOktaImportRule](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.OktaImportRule, *resourcesv1.TeleportOktaImportRule](t, resources.NewOktaImportRuleReconciler, test)
|
||||
}
|
||||
|
||||
func TestOktaImportRuleUpdate(t *testing.T) {
|
||||
t.Skip("Skipping test since okta reconsider is not available in OSS")
|
||||
test := &oktaImportRuleTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.OktaImportRule, *resourcesv1.TeleportOktaImportRule](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.OktaImportRule, *resourcesv1.TeleportOktaImportRule](t, resources.NewOktaImportRuleReconciler, test)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -125,15 +126,15 @@ func (g *opensshEICEServerV2TestingPrimitives) CompareTeleportAndKubernetesResou
|
||||
|
||||
func TestTeleportOpensshEICEServerV2Creation(t *testing.T) {
|
||||
test := &opensshEICEServerV2TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Server, *resourcesv1.TeleportOpenSSHEICEServerV2](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Server, *resourcesv1.TeleportOpenSSHEICEServerV2](t, resources.NewOpenSSHEICEServerV2Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportOpensshEICEServerV2DeletionDrift(t *testing.T) {
|
||||
test := &opensshEICEServerV2TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Server, *resourcesv1.TeleportOpenSSHEICEServerV2](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Server, *resourcesv1.TeleportOpenSSHEICEServerV2](t, resources.NewOpenSSHEICEServerV2Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportOpensshEICEServerV2Update(t *testing.T) {
|
||||
test := &opensshEICEServerV2TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Server, *resourcesv1.TeleportOpenSSHEICEServerV2](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Server, *resourcesv1.TeleportOpenSSHEICEServerV2](t, resources.NewOpenSSHEICEServerV2Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -117,15 +118,15 @@ func (g *opensshServerV2TestingPrimitives) CompareTeleportAndKubernetesResource(
|
||||
|
||||
func TestTeleportOpensshServerV2Creation(t *testing.T) {
|
||||
test := &opensshServerV2TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Server, *resourcesv1.TeleportOpenSSHServerV2](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Server, *resourcesv1.TeleportOpenSSHServerV2](t, resources.NewOpenSSHServerV2Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportOpensshServerV2DeletionDrift(t *testing.T) {
|
||||
test := &opensshServerV2TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Server, *resourcesv1.TeleportOpenSSHServerV2](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Server, *resourcesv1.TeleportOpenSSHServerV2](t, resources.NewOpenSSHServerV2Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportOpensshServerV2Update(t *testing.T) {
|
||||
test := &opensshServerV2TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Server, *resourcesv1.TeleportOpenSSHServerV2](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Server, *resourcesv1.TeleportOpenSSHServerV2](t, resources.NewOpenSSHServerV2Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -27,12 +27,15 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
apimachinerytypes "k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
kclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv2 "github.com/gravitational/teleport/integrations/operator/apis/resources/v2"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -148,17 +151,17 @@ func (g *tokenTestingPrimitives) CompareTeleportAndKubernetesResource(tResource
|
||||
|
||||
func TestProvisionTokenCreation(t *testing.T) {
|
||||
test := &tokenTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.ProvisionToken, *resourcesv2.TeleportProvisionToken](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.ProvisionToken, *resourcesv2.TeleportProvisionToken](t, resources.NewProvisionTokenReconciler, test)
|
||||
}
|
||||
|
||||
func TestProvisionTokenDeletionDrift(t *testing.T) {
|
||||
test := &tokenTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.ProvisionToken, *resourcesv2.TeleportProvisionToken](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.ProvisionToken, *resourcesv2.TeleportProvisionToken](t, resources.NewProvisionTokenReconciler, test)
|
||||
}
|
||||
|
||||
func TestProvisionTokenUpdate(t *testing.T) {
|
||||
test := &tokenTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.ProvisionToken, *resourcesv2.TeleportProvisionToken](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.ProvisionToken, *resourcesv2.TeleportProvisionToken](t, resources.NewProvisionTokenReconciler, test)
|
||||
}
|
||||
|
||||
// This test checks the operator can create Token resources in Teleport for a
|
||||
@@ -172,7 +175,7 @@ func TestProvisionTokenUpdate(t *testing.T) {
|
||||
func TestProvisionTokenCreation_GitHubBot(t *testing.T) {
|
||||
// Test setup
|
||||
ctx := context.Background()
|
||||
setup := setupTestEnv(t)
|
||||
setup := testlib.SetupFakeKubeTestEnv(t)
|
||||
require.NoError(t, teleportCreateDummyRole(ctx, "a", setup.TeleportClient))
|
||||
|
||||
tokenSpecYAML := `
|
||||
@@ -204,10 +207,29 @@ github:
|
||||
obj.SetName(tokenName)
|
||||
obj.SetNamespace(setup.Namespace.Name)
|
||||
|
||||
// Doing the test: we create the TeleportProvisionToken in Kubernetes
|
||||
// Text execution: create the TeleportProvisionToken in Kubernetes
|
||||
err = setup.K8sClient.Create(ctx, obj)
|
||||
require.NoError(t, err)
|
||||
|
||||
reconciler, err := resources.NewProvisionTokenReconciler(setup.K8sClient, setup.TeleportClient)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test execution: Kick off the reconciliation.
|
||||
req := reconcile.Request{
|
||||
NamespacedName: apimachinerytypes.NamespacedName{
|
||||
Namespace: setup.Namespace.Name,
|
||||
Name: tokenName,
|
||||
},
|
||||
}
|
||||
// First reconciliation should set the finalizer and exit.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
// Second reconciliation should create the Teleport resource.
|
||||
// In a real cluster we should receive the event of our own finalizer change
|
||||
// and this wakes us for a second round.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Then we wait for the token to be created in Teleport
|
||||
fastEventually(t, func() bool {
|
||||
tToken, err := setup.TeleportClient.GetToken(ctx, tokenName)
|
||||
@@ -229,14 +251,13 @@ github:
|
||||
|
||||
return true
|
||||
})
|
||||
// Test Teardown
|
||||
|
||||
// Test cleanup: Delete the resource to avoid leftover state if we were running on a real instance.
|
||||
require.NoError(t, setup.K8sClient.Delete(ctx, obj))
|
||||
// We wait for the role deletion in Teleport
|
||||
fastEventually(t, func() bool {
|
||||
_, err := setup.TeleportClient.GetToken(ctx, tokenName)
|
||||
return trace.IsNotFound(err)
|
||||
})
|
||||
require.NoError(t, setup.TeleportClient.DeleteToken(ctx, tokenName))
|
||||
// Kicking of a reconciliation to remove the finalizer and let Kube remove the resource.
|
||||
_, err = reconciler.Reconcile(ctx, req)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func compareTokenSpecs(t *testing.T, expectedUser, actualUser types.ProvisionToken) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -134,15 +135,15 @@ func (g *roleV6TestingPrimitives) CompareTeleportAndKubernetesResource(tResource
|
||||
|
||||
func TestTeleportRoleV6Creation(t *testing.T) {
|
||||
test := &roleV6TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Role, *resourcesv1.TeleportRoleV6](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Role, *resourcesv1.TeleportRoleV6](t, resources.NewRoleV6Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportRoleV6DeletionDrift(t *testing.T) {
|
||||
test := &roleV6TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Role, *resourcesv1.TeleportRoleV6](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Role, *resourcesv1.TeleportRoleV6](t, resources.NewRoleV6Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportRoleV6Update(t *testing.T) {
|
||||
test := &roleV6TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Role, *resourcesv1.TeleportRoleV6](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Role, *resourcesv1.TeleportRoleV6](t, resources.NewRoleV6Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -131,15 +132,15 @@ func (g *roleV7TestingPrimitives) CompareTeleportAndKubernetesResource(tResource
|
||||
|
||||
func TestTeleportRoleV7Creation(t *testing.T) {
|
||||
test := &roleV7TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Role, *resourcesv1.TeleportRoleV7](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Role, *resourcesv1.TeleportRoleV7](t, resources.NewRoleV7Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportRoleV7DeletionDrift(t *testing.T) {
|
||||
test := &roleV7TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Role, *resourcesv1.TeleportRoleV7](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Role, *resourcesv1.TeleportRoleV7](t, resources.NewRoleV7Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportRoleV7Update(t *testing.T) {
|
||||
test := &roleV7TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Role, *resourcesv1.TeleportRoleV7](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Role, *resourcesv1.TeleportRoleV7](t, resources.NewRoleV7Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -133,15 +134,15 @@ func (g *roleV8TestingPrimitives) CompareTeleportAndKubernetesResource(tResource
|
||||
|
||||
func TestTeleportRoleV8Creation(t *testing.T) {
|
||||
test := &roleV8TestingPrimitives{}
|
||||
testlib.ResourceCreationTest[types.Role, *resourcesv1.TeleportRoleV8](t, test)
|
||||
testlib.ResourceCreationSynchronousTest[types.Role, *resourcesv1.TeleportRoleV8](t, resources.NewRoleV8Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportRoleV8DeletionDrift(t *testing.T) {
|
||||
test := &roleV8TestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[types.Role, *resourcesv1.TeleportRoleV8](t, test)
|
||||
testlib.ResourceDeletionDriftSynchronousTest[types.Role, *resourcesv1.TeleportRoleV8](t, resources.NewRoleV8Reconciler, test)
|
||||
}
|
||||
|
||||
func TestTeleportRoleV8Update(t *testing.T) {
|
||||
test := &roleV8TestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[types.Role, *resourcesv1.TeleportRoleV8](t, test)
|
||||
testlib.ResourceUpdateTestSynchronous[types.Role, *resourcesv1.TeleportRoleV8](t, resources.NewRoleV8Reconciler, test)
|
||||
}
|
||||
|
||||
@@ -165,17 +165,32 @@ func (g *accessListTestingPrimitives) CompareTeleportAndKubernetesResource(tReso
|
||||
|
||||
func AccessListCreationTest(t *testing.T, clt *client.Client) {
|
||||
test := &accessListTestingPrimitives{}
|
||||
ResourceCreationTest[*accesslist.AccessList, *resourcesv1.TeleportAccessList](t, test, WithTeleportClient(clt))
|
||||
ResourceCreationSynchronousTest[*accesslist.AccessList, *resourcesv1.TeleportAccessList](
|
||||
t,
|
||||
resources.NewAccessListReconciler,
|
||||
test,
|
||||
WithTeleportClient(clt),
|
||||
)
|
||||
}
|
||||
|
||||
func AccessListDeletionDriftTest(t *testing.T, clt *client.Client) {
|
||||
test := &accessListTestingPrimitives{}
|
||||
ResourceDeletionDriftTest[*accesslist.AccessList, *resourcesv1.TeleportAccessList](t, test, WithTeleportClient(clt))
|
||||
ResourceDeletionDriftSynchronousTest[*accesslist.AccessList, *resourcesv1.TeleportAccessList](
|
||||
t,
|
||||
resources.NewAccessListReconciler,
|
||||
test,
|
||||
WithTeleportClient(clt),
|
||||
)
|
||||
}
|
||||
|
||||
func AccessListUpdateTest(t *testing.T, clt *client.Client) {
|
||||
test := &accessListTestingPrimitives{}
|
||||
ResourceUpdateTest[*accesslist.AccessList, *resourcesv1.TeleportAccessList](t, test, WithTeleportClient(clt))
|
||||
ResourceUpdateTestSynchronous[*accesslist.AccessList, *resourcesv1.TeleportAccessList](
|
||||
t,
|
||||
resources.NewAccessListReconciler,
|
||||
test,
|
||||
WithTeleportClient(clt),
|
||||
)
|
||||
}
|
||||
|
||||
// AccessListMutateExistingTest checks that the operator propagates the expiry
|
||||
|
||||
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types/wrappers"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
)
|
||||
|
||||
type loginRuleTestingPrimitives struct {
|
||||
@@ -146,15 +147,30 @@ func (l *loginRuleTestingPrimitives) CompareTeleportAndKubernetesResource(
|
||||
|
||||
func LoginRuleCreationTest(t *testing.T, clt *client.Client) {
|
||||
test := &loginRuleTestingPrimitives{}
|
||||
ResourceCreationTest[*resourcesv1.LoginRuleResource, *resourcesv1.TeleportLoginRule](t, test, WithTeleportClient(clt))
|
||||
ResourceCreationSynchronousTest[*resourcesv1.LoginRuleResource, *resourcesv1.TeleportLoginRule](
|
||||
t,
|
||||
resources.NewLoginRuleReconciler,
|
||||
test,
|
||||
WithTeleportClient(clt),
|
||||
)
|
||||
}
|
||||
|
||||
func LoginRuleDeletionDriftTest(t *testing.T, clt *client.Client) {
|
||||
test := &loginRuleTestingPrimitives{}
|
||||
ResourceDeletionDriftTest[*resourcesv1.LoginRuleResource, *resourcesv1.TeleportLoginRule](t, test, WithTeleportClient(clt))
|
||||
ResourceDeletionDriftSynchronousTest[*resourcesv1.LoginRuleResource, *resourcesv1.TeleportLoginRule](
|
||||
t,
|
||||
resources.NewLoginRuleReconciler,
|
||||
test,
|
||||
WithTeleportClient(clt),
|
||||
)
|
||||
}
|
||||
|
||||
func LoginRuleUpdateTest(t *testing.T, clt *client.Client) {
|
||||
test := &loginRuleTestingPrimitives{}
|
||||
ResourceUpdateTest[*resourcesv1.LoginRuleResource, *resourcesv1.TeleportLoginRule](t, test, WithTeleportClient(clt))
|
||||
ResourceUpdateTestSynchronous[*resourcesv1.LoginRuleResource, *resourcesv1.TeleportLoginRule](
|
||||
t,
|
||||
resources.NewLoginRuleReconciler,
|
||||
test,
|
||||
WithTeleportClient(clt),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"github.com/gravitational/teleport/api/types"
|
||||
resourcesv1 "github.com/gravitational/teleport/integrations/operator/apis/resources/v1"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/reconcilers"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources"
|
||||
"github.com/gravitational/teleport/integrations/operator/controllers/resources/testlib"
|
||||
)
|
||||
|
||||
@@ -187,24 +188,24 @@ func (g *workloadIdentityTestingPrimitives) CompareTeleportAndKubernetesResource
|
||||
|
||||
func TestWorkloadIdentityCreation(t *testing.T) {
|
||||
test := &workloadIdentityTestingPrimitives{}
|
||||
testlib.ResourceCreationTest[
|
||||
testlib.ResourceCreationSynchronousTest[
|
||||
*workloadidentityv1.WorkloadIdentity,
|
||||
*resourcesv1.TeleportWorkloadIdentityV1,
|
||||
](t, test)
|
||||
](t, resources.NewWorkloadIdentityV1Reconciler, test)
|
||||
}
|
||||
|
||||
func TestWorkloadIdentityDeletionDrift(t *testing.T) {
|
||||
test := &workloadIdentityTestingPrimitives{}
|
||||
testlib.ResourceDeletionDriftTest[
|
||||
testlib.ResourceDeletionDriftSynchronousTest[
|
||||
*workloadidentityv1.WorkloadIdentity,
|
||||
*resourcesv1.TeleportWorkloadIdentityV1,
|
||||
](t, test)
|
||||
](t, resources.NewWorkloadIdentityV1Reconciler, test)
|
||||
}
|
||||
|
||||
func TestWorkloadIdentityUpdate(t *testing.T) {
|
||||
test := &workloadIdentityTestingPrimitives{}
|
||||
testlib.ResourceUpdateTest[
|
||||
testlib.ResourceUpdateTestSynchronous[
|
||||
*workloadidentityv1.WorkloadIdentity,
|
||||
*resourcesv1.TeleportWorkloadIdentityV1,
|
||||
](t, test)
|
||||
](t, resources.NewWorkloadIdentityV1Reconciler, test)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user