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

add IAM Auth Policy dummy controller #443

Merged
merged 1 commit into from
Oct 19, 2023
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
19 changes: 12 additions & 7 deletions cmd/aws-application-networking-k8s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ func addOptionalCRDs(scheme *runtime.Scheme) {
scheme.AddKnownTypes(dnsEndpoint, &endpoint.DNSEndpoint{}, &endpoint.DNSEndpointList{})
metav1.AddToGroupVersion(scheme, dnsEndpoint)

awsGatewayControllerCRDGroupVersion := schema.GroupVersion{
groupVersion := schema.GroupVersion{
Group: anv1alpha1.GroupName,
Version: "v1alpha1",
}
scheme.AddKnownTypes(awsGatewayControllerCRDGroupVersion, &anv1alpha1.TargetGroupPolicy{}, &anv1alpha1.TargetGroupPolicyList{})
metav1.AddToGroupVersion(scheme, awsGatewayControllerCRDGroupVersion)

scheme.AddKnownTypes(awsGatewayControllerCRDGroupVersion, &anv1alpha1.VpcAssociationPolicy{}, &anv1alpha1.VpcAssociationPolicyList{})
metav1.AddToGroupVersion(scheme, awsGatewayControllerCRDGroupVersion)
scheme.AddKnownTypes(groupVersion,
&anv1alpha1.TargetGroupPolicy{}, &anv1alpha1.TargetGroupPolicyList{},
&anv1alpha1.AccessLogPolicy{}, &anv1alpha1.AccessLogPolicyList{},
&anv1alpha1.VpcAssociationPolicy{}, &anv1alpha1.VpcAssociationPolicyList{},
&anv1alpha1.IAMAuthPolicy{}, &anv1alpha1.IAMAuthPolicyList{})

scheme.AddKnownTypes(awsGatewayControllerCRDGroupVersion, &anv1alpha1.AccessLogPolicy{}, &anv1alpha1.AccessLogPolicyList{})
metav1.AddToGroupVersion(scheme, awsGatewayControllerCRDGroupVersion)
metav1.AddToGroupVersion(scheme, groupVersion)
}

func main() {
Expand Down Expand Up @@ -186,6 +186,11 @@ func main() {
setupLog.Fatalf("accesslogpolicy controller setup failed: %s", err)
}

err = controllers.RegisterIAMAuthPolicyController(ctrlLog.Named("iam-auth-policy"), mgr)
if err != nil {
setupLog.Fatalf("iam auth policy controller setup failed: %s", err)
}

go latticestore.GetDefaultLatticeDataStore().ServeIntrospection()

//+kubebuilder:scaffold:builder
Expand Down
68 changes: 68 additions & 0 deletions controllers/iamauthpolicy_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package controllers

import (
"context"
"fmt"

anv1alpha1 "github.com/aws/aws-application-networking-k8s/pkg/apis/applicationnetworking/v1alpha1"
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"

k8serr "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type IAMAuthPolicyController struct {
log gwlog.Logger
client client.Client
}

func RegisterIAMAuthPolicyController(log gwlog.Logger, mgr ctrl.Manager) error {
controller := &IAMAuthPolicyController{
log: log,
client: mgr.GetClient(),
}
err := ctrl.NewControllerManagedBy(mgr).
For(&anv1alpha1.IAMAuthPolicy{}).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add the pkg_builder.WithPredicates(predicate.GenerationChangedPredicate{}) in the later PRs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GenerationChangedPredicate description is a bit vague to me. Especially "Caveats" section. Why do we use this?

Complete(controller)
return err
}

func (c *IAMAuthPolicyController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
c.log.Infow("reconcile", "req", req)

policy := &anv1alpha1.IAMAuthPolicy{}
err := c.client.Get(ctx, req.NamespacedName, policy)
if !k8serr.IsNotFound(err) {
return ctrl.Result{}, err
}

switch policy.Spec.TargetRef.Kind {
case "Gateway":
err = c.reconcileGateway(ctx, policy)
break
case "HTTPRoute":
case "GRPCRoute":
err = c.reconcileRoute(ctx, policy)
break
default:
err = fmt.Errorf("unsupported targetRef type, req=%s, kind=%s",
req, policy.Spec.TargetRef.Kind)
}
if err != nil {
return ctrl.Result{}, err
}

c.log.Infow("successfully reconciled", "req", req)
return ctrl.Result{}, nil
}

func (c *IAMAuthPolicyController) reconcileGateway(ctx context.Context, policy *anv1alpha1.IAMAuthPolicy) error {
c.log.Debugw("reconcile gateway iam policy", "policy", policy)
return nil
}

func (c IAMAuthPolicyController) reconcileRoute(ctx context.Context, policy *anv1alpha1.IAMAuthPolicy) error {
c.log.Debugw("reconcile route iam policy", "policy", policy)
return nil
}