Skip to content

Commit

Permalink
controller-runtime v0.19.0 fixups (and de-linting)
Browse files Browse the repository at this point in the history
- Changes to reconciler-related types pursuant to kubernetes-sigs/controller-runtime#2799
- Removal of yellow squiggles

HIVE-2616
  • Loading branch information
2uasimojo committed Oct 3, 2024
1 parent 5b4fe1d commit 52496e2
Show file tree
Hide file tree
Showing 40 changed files with 141 additions and 151 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/argocdregister/argocdregister_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewReconciler(mgr manager.Manager, logger log.FieldLogger, rateLimiter flow
}

// AddToManager adds a new Controller to mgr with r as the reconcile.Reconciler
func AddToManager(mgr manager.Manager, r reconcile.Reconciler, concurrentReconciles int, rateLimiter workqueue.RateLimiter) error {
func AddToManager(mgr manager.Manager, r reconcile.Reconciler, concurrentReconciles int, rateLimiter workqueue.TypedRateLimiter[reconcile.Request]) error {
// Create a new controller
c, err := controller.New("argocdregister-controller", mgr, controller.Options{
Reconciler: controllerutils.NewDelayingReconciler(r, log.WithField("controller", ControllerName)),
Expand Down
22 changes: 5 additions & 17 deletions pkg/controller/argocdregister/argocdregister_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ func TestArgoCDRegisterReconcile(t *testing.T) {
testSecret(corev1.SecretTypeDockerConfigJson, constants.GetMergedPullSecretName(testClusterDeployment()), corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, credsSecret, corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, "foo-lqmsh-admin-kubeconfig", "kubeconfig", "{}"),
testServiceAccount("argocd-server", argoCDDefaultNamespace,
corev1.ObjectReference{Kind: "Secret",
Name: "argocd-token",
Namespace: argoCDDefaultNamespace}),
testServiceAccount("argocd-server", []corev1.ObjectReference{{Kind: "Secret", Name: "argocd-token", Namespace: argoCDDefaultNamespace}}...),
testSecretWithNamespace(corev1.SecretTypeDockerConfigJson, "argocd-token", argoCDDefaultNamespace, "token", "{}"),
},
argoCDEnabled: true,
Expand All @@ -117,10 +114,7 @@ func TestArgoCDRegisterReconcile(t *testing.T) {
testSecret(corev1.SecretTypeDockerConfigJson, constants.GetMergedPullSecretName(testClusterDeployment()), corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, credsSecret, corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, "foo-lqmsh-admin-kubeconfig", "kubeconfig", "{}"),
testServiceAccount("argocd-server", argoCDDefaultNamespace,
corev1.ObjectReference{Kind: "Secret",
Name: "argocd-token",
Namespace: argoCDDefaultNamespace}),
testServiceAccount("argocd-server", []corev1.ObjectReference{{Kind: "Secret", Name: "argocd-token", Namespace: argoCDDefaultNamespace}}...),
testSecretWithNamespace(corev1.SecretTypeDockerConfigJson, "argocd-token", argoCDDefaultNamespace, "token", "{}"),
// Existing ArgoCD cluster secret
testSecretWithNamespace(corev1.SecretTypeDockerConfigJson, "cluster-test-api.test.com-2774145043", argoCDDefaultNamespace, "test", "{}"),
Expand Down Expand Up @@ -148,10 +142,7 @@ func TestArgoCDRegisterReconcile(t *testing.T) {
testSecret(corev1.SecretTypeDockerConfigJson, constants.GetMergedPullSecretName(testClusterDeployment()), corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, credsSecret, corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, "foo-lqmsh-admin-kubeconfig", "kubeconfig", "{}"),
testServiceAccount("argocd-server", argoCDDefaultNamespace,
corev1.ObjectReference{Kind: "Secret",
Name: "argocd-token",
Namespace: argoCDDefaultNamespace}),
testServiceAccount("argocd-server", []corev1.ObjectReference{{Kind: "Secret", Name: "argocd-token", Namespace: argoCDDefaultNamespace}}...),
testSecretWithNamespace(corev1.SecretTypeDockerConfigJson, "argocd-token", argoCDDefaultNamespace, "token", "{}"),
// Existing ArgoCD cluster secret
testSecretWithNamespace(corev1.SecretTypeDockerConfigJson, "cluster-test-api.test.com-2774145043", argoCDDefaultNamespace, corev1.DockerConfigJsonKey, "{}"),
Expand All @@ -173,10 +164,7 @@ func TestArgoCDRegisterReconcile(t *testing.T) {
testSecret(corev1.SecretTypeDockerConfigJson, constants.GetMergedPullSecretName(testClusterDeployment()), corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, credsSecret, corev1.DockerConfigJsonKey, "{}"),
testSecret(corev1.SecretTypeDockerConfigJson, "foo-lqmsh-admin-kubeconfig", "kubeconfig", "{}"),
testServiceAccount("argocd-server", argoCDDefaultNamespace,
corev1.ObjectReference{Kind: "Secret",
Name: "argocd-token",
Namespace: argoCDDefaultNamespace}),
testServiceAccount("argocd-server", []corev1.ObjectReference{{Kind: "Secret", Name: "argocd-token", Namespace: argoCDDefaultNamespace}}...),
testSecretWithNamespace(corev1.SecretTypeDockerConfigJson, "argocd-token", argoCDDefaultNamespace, "token", "{}"),
},
argoCDEnabled: false,
Expand Down Expand Up @@ -329,7 +317,7 @@ func testSecretWithNamespace(secretType corev1.SecretType, name, namespace, key,
return s
}

func testServiceAccount(name, namespace string, secrets ...corev1.ObjectReference) *corev1.ServiceAccount {
func testServiceAccount(name string, secrets ...corev1.ObjectReference) *corev1.ServiceAccount {
return &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down
31 changes: 17 additions & 14 deletions pkg/controller/awsprivatelink/awsprivatelink_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NewReconciler(mgr manager.Manager, rateLimiter flowcontrol.RateLimiter) (*R
}

// AddToManager adds a new Controller to mgr with r as the reconcile.Reconciler
func AddToManager(mgr manager.Manager, r *ReconcileAWSPrivateLink, concurrentReconciles int, rateLimiter workqueue.RateLimiter) error {
func AddToManager(mgr manager.Manager, r *ReconcileAWSPrivateLink, concurrentReconciles int, rateLimiter workqueue.TypedRateLimiter[reconcile.Request]) error {
// Create a new controller
c, err := controller.New("awsprivatelink-controller", mgr, controller.Options{
Reconciler: controllerutils.NewDelayingReconciler(r, log.WithField("controller", ControllerName)),
Expand Down Expand Up @@ -546,7 +546,7 @@ func (r *ReconcileAWSPrivateLink) reconcilePrivateLink(cd *hivev1.ClusterDeploym
}

// Create the Private Hosted Zone for the VPC Endpoint.
hzModified, hostedZoneID, err := r.reconcileHostedZone(awsClient, cd, clusterMetadata, vpcEndpoint, apiDomain, logger)
hzModified, hostedZoneID, err := r.reconcileHostedZone(awsClient, cd, vpcEndpoint, apiDomain, logger)
if err != nil {
logger.WithError(err).Error("could not reconcile the Hosted Zone")

Expand All @@ -568,7 +568,7 @@ func (r *ReconcileAWSPrivateLink) reconcilePrivateLink(cd *hivev1.ClusterDeploym
}

// Associate the VPCs to the hosted zone.
associationsModified, err := r.reconcileHostedZoneAssociations(awsClient, cd, hostedZoneID, vpcEndpoint, logger)
associationsModified, err := r.reconcileHostedZoneAssociations(awsClient, hostedZoneID, vpcEndpoint, logger)
if err != nil {
logger.WithError(err).Error("could not reconcile the associations of the Hosted Zone")

Expand Down Expand Up @@ -763,7 +763,7 @@ func (r *ReconcileAWSPrivateLink) reconcileVPCEndpointService(awsClient *awsClie
cd.Status.Platform.AWS.PrivateLink.VPCEndpointService.AdditionalAllowedPrincipals = &desiredPermsSlice
}
cd.Status.Platform.AWS.PrivateLink.VPCEndpointService.DefaultAllowedPrincipal = &defaultARN
if err := r.updatePrivateLinkStatus(cd, logger); err != nil {
if err := r.updatePrivateLinkStatus(cd); err != nil {
logger.WithError(err).Error("error updating clusterdeployment status with vpcEndpointService additionalAllowedPrincipals")
return modified, nil, err
}
Expand All @@ -787,7 +787,7 @@ func (r *ReconcileAWSPrivateLink) ensureVPCEndpointService(awsClient awsclient.C
}
if len(resp.ServiceConfigurations) == 0 {
modified = true
serviceConfig, err = createVPCEndpointService(awsClient, cd, metadata, clusterNLB, logger)
serviceConfig, err = createVPCEndpointService(awsClient, metadata, clusterNLB, logger)
if err != nil {
logger.WithError(err).Error("failed to create VPC Endpoint Service for cluster")
return modified, nil, errors.Wrap(err, "failed to create VPC Endpoint Service for cluster")
Expand All @@ -801,15 +801,15 @@ func (r *ReconcileAWSPrivateLink) ensureVPCEndpointService(awsClient awsclient.C
ID: *serviceConfig.ServiceId,
Name: *serviceConfig.ServiceName,
}
if err := r.updatePrivateLinkStatus(cd, logger); err != nil {
if err := r.updatePrivateLinkStatus(cd); err != nil {
logger.WithError(err).Error("error updating clusterdeployment status with vpcEndpointService")
return modified, nil, err
}

return modified, serviceConfig, nil
}

func createVPCEndpointService(awsClient awsclient.Client, cd *hivev1.ClusterDeployment, metadata *hivev1.ClusterMetadata, clusterNLB string, logger log.FieldLogger) (*ec2.ServiceConfiguration, error) {
func createVPCEndpointService(awsClient awsclient.Client, metadata *hivev1.ClusterMetadata, clusterNLB string, logger log.FieldLogger) (*ec2.ServiceConfiguration, error) {
resp, err := awsClient.CreateVpcEndpointServiceConfiguration(&ec2.CreateVpcEndpointServiceConfigurationInput{
AcceptanceRequired: aws.Bool(false),
NetworkLoadBalancerArns: aws.StringSlice([]string{clusterNLB}),
Expand Down Expand Up @@ -875,7 +875,7 @@ func (r *ReconcileAWSPrivateLink) reconcileVPCEndpoint(awsClient *awsClient,

initPrivateLinkStatus(cd)
cd.Status.Platform.AWS.PrivateLink.VPCEndpointID = *vpcEndpoint.VpcEndpointId
if err := r.updatePrivateLinkStatus(cd, logger); err != nil {
if err := r.updatePrivateLinkStatus(cd); err != nil {
logger.WithError(err).Error("error updating clusterdeployment status with vpcEndpointID")
return modified, nil, err
}
Expand Down Expand Up @@ -931,7 +931,7 @@ func (r *ReconcileAWSPrivateLink) createVPCEndpoint(awsClient awsclient.Client,
// where VPC endpoint was created. It also make sure the DNS zone has an ALIAS record pointing
// to the regional DNS name of the VPC endpoint.
func (r *ReconcileAWSPrivateLink) reconcileHostedZone(awsClient *awsClient,
cd *hivev1.ClusterDeployment, metadata *hivev1.ClusterMetadata,
cd *hivev1.ClusterDeployment,
vpcEndpoint *ec2.VpcEndpoint, apiDomain string,
logger log.FieldLogger) (bool, string, error) {
modified, hostedZoneID, err := r.ensureHostedZone(awsClient.hub, cd, vpcEndpoint, apiDomain, logger)
Expand Down Expand Up @@ -1015,7 +1015,11 @@ func (r *ReconcileAWSPrivateLink) ensureHostedZone(awsClient awsclient.Client,
endpoint *ec2.VpcEndpoint, apiDomain string,
logger log.FieldLogger) (bool, string, error) {
modified := false
hzID, err := findHostedZone(awsClient, *endpoint.VpcId, cd.Spec.Platform.AWS.Region, apiDomain, logger)
var (
hzID string
err error
)
hzID, err = findHostedZone(awsClient, *endpoint.VpcId, cd.Spec.Platform.AWS.Region, apiDomain)
if err != nil && errors.Is(err, errNoHostedZoneFoundForVPC) {
modified = true
hzID, err = r.createHostedZone(awsClient, cd, endpoint, apiDomain, logger)
Expand All @@ -1030,7 +1034,7 @@ func (r *ReconcileAWSPrivateLink) ensureHostedZone(awsClient awsclient.Client,

initPrivateLinkStatus(cd)
cd.Status.Platform.AWS.PrivateLink.HostedZoneID = hzID
if err := r.updatePrivateLinkStatus(cd, logger); err != nil {
if err := r.updatePrivateLinkStatus(cd); err != nil {
logger.WithError(err).Error("failed to update the hosted zone ID for cluster deployment")
return modified, "", err
}
Expand All @@ -1043,7 +1047,7 @@ var errNoHostedZoneFoundForVPC = errors.New("no hosted zone found")
// findHostedZone finds a Private Hosted Zone for apiDomain that is associated with the given
// VPC.
// If no such hosted zone exists, it return an errNoHostedZoneFoundForVPC error.
func findHostedZone(awsClient awsclient.Client, vpcID, vpcRegion, apiDomain string, logger log.FieldLogger) (string, error) {
func findHostedZone(awsClient awsclient.Client, vpcID, vpcRegion, apiDomain string) (string, error) {
input := &route53.ListHostedZonesByVPCInput{
VPCId: aws.String(vpcID),
VPCRegion: aws.String(vpcRegion),
Expand Down Expand Up @@ -1097,7 +1101,6 @@ func (r *ReconcileAWSPrivateLink) createHostedZone(awsClient awsclient.Client,
// reconcileHostedZoneAssociations ensures that the all the VPCs in the associatedVPCs list from
// the controller config are associated to the PHZ hostedZoneID.
func (r *ReconcileAWSPrivateLink) reconcileHostedZoneAssociations(awsClient *awsClient,
cd *hivev1.ClusterDeployment,
hostedZoneID string, vpcEndpoint *ec2.VpcEndpoint,
logger log.FieldLogger) (bool, error) {
hzLog := logger.WithField("hostedZoneID", hostedZoneID)
Expand Down Expand Up @@ -1362,7 +1365,7 @@ var retryBackoff = wait.Backoff{
Jitter: 0.1,
}

func (r *ReconcileAWSPrivateLink) updatePrivateLinkStatus(cd *hivev1.ClusterDeployment, logger log.FieldLogger) error {
func (r *ReconcileAWSPrivateLink) updatePrivateLinkStatus(cd *hivev1.ClusterDeployment) error {
return retry.RetryOnConflict(retryBackoff, func() error {
curr := &hivev1.ClusterDeployment{}
err := r.Client.Get(context.TODO(), types.NamespacedName{Namespace: cd.Namespace, Name: cd.Name}, curr)
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/awsprivatelink/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ func (r *ReconcileAWSPrivateLink) cleanupPrivateLink(cd *hivev1.ClusterDeploymen
logger.WithError(err).Error("error cleaning up Hosted Zone")
return err
}
if err := r.cleanupVPCEndpoint(awsClient.hub, cd, metadata, logger); err != nil {
if err := r.cleanupVPCEndpoint(awsClient.hub, metadata, logger); err != nil {
logger.WithError(err).Error("error cleaning up VPCEndpoint")
return err
}
if err := r.cleanupVPCEndpointService(awsClient.user, cd, metadata, logger); err != nil {
if err := r.cleanupVPCEndpointService(awsClient.user, metadata, logger); err != nil {
logger.WithError(err).Error("error cleaning up VPCEndpoint Service")
return err
}

initPrivateLinkStatus(cd)
cd.Status.Platform.AWS.PrivateLink = nil
if err := r.updatePrivateLinkStatus(cd, logger); err != nil {
if err := r.updatePrivateLinkStatus(cd); err != nil {
logger.WithError(err).Error("error updating clusterdeployment after cleanup of private link")
return err
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (r *ReconcileAWSPrivateLink) cleanupHostedZone(awsClient awsclient.Client,
}

vpcEndpoint := endpointResp.VpcEndpoints[0]
hzID, err = findHostedZone(awsClient, *vpcEndpoint.VpcId, cd.Spec.Platform.AWS.Region, apiDomain, logger)
hzID, err = findHostedZone(awsClient, *vpcEndpoint.VpcId, cd.Spec.Platform.AWS.Region, apiDomain)
if err != nil && errors.Is(err, errNoHostedZoneFoundForVPC) {
return nil // no work
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func (r *ReconcileAWSPrivateLink) cleanupHostedZone(awsClient awsclient.Client,
}

func (r *ReconcileAWSPrivateLink) cleanupVPCEndpoint(awsClient awsclient.Client,
cd *hivev1.ClusterDeployment, metadata *hivev1.ClusterMetadata,
metadata *hivev1.ClusterMetadata,
logger log.FieldLogger) error {
idLog := logger.WithField("infraID", metadata.InfraID)
resp, err := awsClient.DescribeVpcEndpoints(&ec2.DescribeVpcEndpointsInput{
Expand Down Expand Up @@ -243,7 +243,7 @@ func (r *ReconcileAWSPrivateLink) cleanupVPCEndpoint(awsClient awsclient.Client,
}

func (r *ReconcileAWSPrivateLink) cleanupVPCEndpointService(awsClient awsclient.Client,
cd *hivev1.ClusterDeployment, metadata *hivev1.ClusterMetadata,
metadata *hivev1.ClusterMetadata,
logger log.FieldLogger) error {
idLog := logger.WithField("infraID", metadata.InfraID)
resp, err := awsClient.DescribeVpcEndpointServiceConfigurations(&ec2.DescribeVpcEndpointServiceConfigurationsInput{
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/clusterclaim/clusterclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewReconciler(mgr manager.Manager, rateLimiter flowcontrol.RateLimiter) *Re
}

// AddToManager adds a new Controller to mgr with r as the reconcile.Reconciler
func AddToManager(mgr manager.Manager, r *ReconcileClusterClaim, concurrentReconciles int, rateLimiter workqueue.RateLimiter) error {
func AddToManager(mgr manager.Manager, r *ReconcileClusterClaim, concurrentReconciles int, rateLimiter workqueue.TypedRateLimiter[reconcile.Request]) error {
// Create a new controller
c, err := controller.New("clusterclaim-controller", mgr, controller.Options{
Reconciler: controllerutils.NewDelayingReconciler(r, r.logger),
Expand Down Expand Up @@ -122,7 +122,7 @@ func requestsForClusterDeployment(ctx context.Context, cd *hivev1.ClusterDeploym
return []reconcile.Request{{NamespacedName: *claim}}
}

func requestsForRBACResourcesRole(c client.Client, resourceName string, logger log.FieldLogger) handler.TypedMapFunc[*rbacv1.Role] {
func requestsForRBACResourcesRole(c client.Client, resourceName string, logger log.FieldLogger) handler.TypedMapFunc[*rbacv1.Role, reconcile.Request] {
return func(ctx context.Context, o *rbacv1.Role) []reconcile.Request {
if o.GetName() != resourceName {
return nil
Expand All @@ -141,7 +141,7 @@ func requestsForRBACResourcesRole(c client.Client, resourceName string, logger l
}
}

func requestsForRBACResourcesRoleBinding(c client.Client, resourceName string, logger log.FieldLogger) handler.TypedMapFunc[*rbacv1.RoleBinding] {
func requestsForRBACResourcesRoleBinding(c client.Client, resourceName string, logger log.FieldLogger) handler.TypedMapFunc[*rbacv1.RoleBinding, reconcile.Request] {
return func(ctx context.Context, o *rbacv1.RoleBinding) []reconcile.Request {
if o.GetName() != resourceName {
return nil
Expand Down Expand Up @@ -534,7 +534,7 @@ func (r *ReconcileClusterClaim) createRBAC(claim *hivev1.ClusterClaim, cd *hivev
if cd.Spec.ClusterMetadata == nil {
return errors.New("ClusterDeployment does not have ClusterMetadata")
}
if err := r.applyHiveClaimOwnerRole(claim, cd, logger); err != nil {
if err := r.applyHiveClaimOwnerRole(cd, logger); err != nil {
return err
}
if err := r.applyHiveClaimOwnerRoleBinding(claim, cd, logger); err != nil {
Expand All @@ -543,7 +543,7 @@ func (r *ReconcileClusterClaim) createRBAC(claim *hivev1.ClusterClaim, cd *hivev
return nil
}

func (r *ReconcileClusterClaim) applyHiveClaimOwnerRole(claim *hivev1.ClusterClaim, cd *hivev1.ClusterDeployment, logger log.FieldLogger) error {
func (r *ReconcileClusterClaim) applyHiveClaimOwnerRole(cd *hivev1.ClusterDeployment, logger log.FieldLogger) error {
desiredRole := &rbacv1.Role{
ObjectMeta: metav1.ObjectMeta{
Namespace: cd.Namespace,
Expand Down
5 changes: 1 addition & 4 deletions pkg/controller/clusterclaim/clusterclaim_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,7 @@ func Test_getClaimLifetime(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
var poolLifetime *hivev1.ClusterPoolClaimLifetime
if test.defaultLifetime != nil {
if poolLifetime == nil {
poolLifetime = &hivev1.ClusterPoolClaimLifetime{}
}
poolLifetime.Default = test.defaultLifetime
poolLifetime = &hivev1.ClusterPoolClaimLifetime{Default: test.defaultLifetime}
}
if test.maximumLifetime != nil {
if poolLifetime == nil {
Expand Down
Loading

0 comments on commit 52496e2

Please sign in to comment.