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

curated packages full cluster lifecycle adaptations #4970

Merged
merged 5 commits into from
Mar 15, 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
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ mocks: ## Generate mocks
${MOCKGEN} -destination=pkg/curatedpackages/mocks/bundlemanager.go -package=mocks -source "pkg/curatedpackages/bundlemanager.go" Manager
${MOCKGEN} -destination=pkg/clients/kubernetes/mocks/kubectl.go -package=mocks -source "pkg/clients/kubernetes/unauth.go"
${MOCKGEN} -destination=pkg/clients/kubernetes/mocks/kubeconfig.go -package=mocks -source "pkg/clients/kubernetes/kubeconfig.go"
${MOCKGEN} -destination=pkg/curatedpackages/mocks/installer.go -package=mocks -source "pkg/curatedpackages/packagecontrollerclient.go" ChartInstaller
${MOCKGEN} -destination=pkg/curatedpackages/mocks/installer.go -package=mocks -source "pkg/curatedpackages/packagecontrollerclient.go" ChartInstaller ChartUninstaller ClientBuilder
${MOCKGEN} -destination=pkg/curatedpackages/mocks/kube_client.go -package=mocks -mock_names Client=MockKubeClient sigs.k8s.io/controller-runtime/pkg/client Client
${MOCKGEN} -destination=pkg/cluster/mocks/client_builder.go -package=mocks -source "pkg/cluster/client_builder.go"
${MOCKGEN} -destination=controllers/mocks/factory.go -package=mocks "github.com/aws/eks-anywhere/controllers" Manager
${MOCKGEN} -destination=pkg/networking/cilium/reconciler/mocks/templater.go -package=mocks -source "pkg/networking/cilium/reconciler/reconciler.go"
Expand All @@ -585,7 +586,7 @@ mocks: ## Generate mocks
${MOCKGEN} -destination=pkg/providers/docker/reconciler/mocks/reconciler.go -package=mocks -source "pkg/providers/docker/reconciler/reconciler.go"
${MOCKGEN} -destination=pkg/providers/tinkerbell/reconciler/mocks/reconciler.go -package=mocks -source "pkg/providers/tinkerbell/reconciler/reconciler.go"
${MOCKGEN} -destination=pkg/awsiamauth/reconciler/mocks/reconciler.go -package=mocks -source "pkg/awsiamauth/reconciler/reconciler.go"
${MOCKGEN} -destination=controllers/mocks/cluster_controller.go -package=mocks -source "controllers/cluster_controller.go" AWSIamConfigReconciler ClusterValidator
${MOCKGEN} -destination=controllers/mocks/cluster_controller.go -package=mocks -source "controllers/cluster_controller.go" AWSIamConfigReconciler ClusterValidator PackageControllerClient
${MOCKGEN} -destination=pkg/workflow/task_mock_test.go -package=workflow_test -source "pkg/workflow/task.go"
${MOCKGEN} -destination=pkg/validations/createcluster/mocks/createcluster.go -package=mocks -source "pkg/validations/createcluster/createcluster.go"
${MOCKGEN} -destination=pkg/awsiamauth/mock_test.go -package=awsiamauth_test -source "pkg/awsiamauth/installer.go"
Expand Down
2 changes: 1 addition & 1 deletion cmd/eksctl-anywhere/cmd/installpackagecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func installPackageController(ctx context.Context) error {
}

curatedpackages.PrintLicense()
err = ctrlClient.EnableCuratedPackages(ctx)
err = ctrlClient.Enable(ctx)
ewollesen marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions config/manifest/eksa-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6024,6 +6024,18 @@ rules:
- patch
- update
- watch
- apiGroups:
- packages.eks.amazonaws.com
resources:
- packagebundlecontrollers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- tinkerbell.org
resources:
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ rules:
- patch
- update
- watch
- apiGroups:
- packages.eks.amazonaws.com
resources:
- packagebundlecontrollers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- tinkerbell.org
resources:
Expand Down
29 changes: 28 additions & 1 deletion controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import (
"github.com/aws/eks-anywhere/pkg/controller/clientutil"
"github.com/aws/eks-anywhere/pkg/controller/clusters"
"github.com/aws/eks-anywhere/pkg/controller/handlers"
"github.com/aws/eks-anywhere/pkg/curatedpackages"
"github.com/aws/eks-anywhere/pkg/registrymirror"
"github.com/aws/eks-anywhere/pkg/utils/ptr"
"github.com/aws/eks-anywhere/release/api/v1alpha1"
)

const (
Expand All @@ -42,6 +45,15 @@ type ClusterReconciler struct {
providerReconcilerRegistry ProviderClusterReconcilerRegistry
awsIamAuth AWSIamConfigReconciler
clusterValidator ClusterValidator
packagesClient PackagesClient
}

// PackagesClient handles curated packages operations from within the cluster
// controller.
type PackagesClient interface {
EnableFullLifecycle(ctx context.Context, log logr.Logger, clusterName string, kubeConfig string, chart *v1alpha1.Image, registry *registrymirror.RegistryMirror, options ...curatedpackages.PackageControllerClientOpt) error
ReconcileDelete(context.Context, logr.Logger, curatedpackages.KubeDeleter, *anywherev1.Cluster) error
Reconcile(context.Context, logr.Logger, client.Client, *anywherev1.Cluster) error
}

type ProviderClusterReconcilerRegistry interface {
Expand All @@ -61,12 +73,13 @@ type ClusterValidator interface {
}

// NewClusterReconciler constructs a new ClusterReconciler.
func NewClusterReconciler(client client.Client, registry ProviderClusterReconcilerRegistry, awsIamAuth AWSIamConfigReconciler, clusterValidator ClusterValidator) *ClusterReconciler {
func NewClusterReconciler(client client.Client, registry ProviderClusterReconcilerRegistry, awsIamAuth AWSIamConfigReconciler, clusterValidator ClusterValidator, pkgs PackagesClient) *ClusterReconciler {
ewollesen marked this conversation as resolved.
Show resolved Hide resolved
return &ClusterReconciler{
client: client,
providerReconcilerRegistry: registry,
awsIamAuth: awsIamAuth,
clusterValidator: clusterValidator,
packagesClient: pkgs,
}
}

Expand Down Expand Up @@ -266,6 +279,14 @@ func (r *ClusterReconciler) postClusterProviderReconcile(ctx context.Context, lo
}
}

// Self-managed clusters can support curated packages, but that support
// comes from the CLI at this time.
if cluster.IsManaged() && cluster.IsPackagesEnabled() {
if err := r.packagesClient.Reconcile(ctx, log, r.client, cluster); err != nil {
return controller.Result{}, err
}
}

return controller.Result{}, nil
}

Expand Down Expand Up @@ -314,6 +335,12 @@ func (r *ClusterReconciler) reconcileDelete(ctx context.Context, log logr.Logger
}
}

if cluster.IsManaged() {
if err := r.packagesClient.ReconcileDelete(ctx, log, r.client, cluster); err != nil {
return ctrl.Result{}, fmt.Errorf("deleting packages for cluster %q: %w", cluster.Name, err)
}
}

return ctrl.Result{}, nil
}

Expand Down
7 changes: 7 additions & 0 deletions controllers/cluster_controller_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func NewClusterReconcilerLegacy(client client.Client, log logr.Logger, scheme *r
// +kubebuilder:rbac:groups="",namespace=eksa-system,resources=secrets,verbs=delete;
// +kubebuilder:rbac:groups=tinkerbell.org,resources=hardware;hardware/status,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=bmc.tinkerbell.org,resources=machines;machines/status,verbs=get;list;watch
//
// For the full cluster lifecycle to support Curated Packages, the controller
// must be able to create, delete, update, and patch package bundle controller
// resources, which will trigger the curated packages controller to do the
// rest.
//
// +kubebuilder:rbac:groups=packages.eks.amazonaws.com,resources=packagebundlecontrollers,verbs=create;delete;get;list;patch;update;watch;
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of adding this comment then? Generally we don't need to backport to legacy controller anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the only place I found to add these comments that was actually reflected in the final output. Can you suggest a better place to put them?

Copy link
Member

Choose a reason for hiding this comment

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

This file is for the old controller, so I would suggest to try in cluster_controller.go. Or if it's not applicable then omit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try again, but the last time I made modifications there, they plain just didn't show up... Which seemed weird, but maybe I was using the wrong makefile target... or something.


// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
Loading