Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Install TKR package contents directly
Browse files Browse the repository at this point in the history
TKR package contents get automatically installed without the use of
Carvel PackageInstall resource (which doesn't support shared resources
across packages).

This is necessary because a TKR package may contain resources that are
reused by other TKR packages, e.g. different TKRs shipping the same
Kubernetes version may share some OSImages or addon packages
(addon packages may even be reused across K8s versions).

Inject Registry as an interface

This improves testability and modularity of affected components, and
reuse of Registry as a component. Now, both Fetcher and TKR Package
Reconciler re-use the same Registry instance provided externally.

Only fetch compatible TKR BOMs and TKR packages

We're also now using compatibility information to download only
compatible TKR packages and TKR BOMs into the management cluster.

Signed-off-by: Ivan Mikushin <imikushin@vmware.com>
  • Loading branch information
Ivan Mikushin committed Jun 1, 2022
1 parent 041cb8a commit 665627e
Show file tree
Hide file tree
Showing 12 changed files with 721 additions and 245 deletions.
2 changes: 1 addition & 1 deletion pkg/v1/tkr/controllers/source/tkr_source_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/go-logr/logr"
ctlimg "github.com/k14s/imgpkg/pkg/imgpkg/registry"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/yaml"

runv1 "github.com/vmware-tanzu/tanzu-framework/apis/run/v1alpha1"
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkr/pkg/constants"
Expand Down
4 changes: 2 additions & 2 deletions pkg/v1/tkr/pkg/types/bommetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package types

// ManagementClusterVersion contains kubernetes versions that are supported by the management cluster with a certain TKG version.
type ManagementClusterVersion struct {
TKGVersion string `yaml:"version"`
SupportedKubernetesVersions []string `yaml:"supportedKubernetesVersions"`
TKGVersion string `json:"version"`
SupportedKubernetesVersions []string `json:"supportedKubernetesVersions"`
}

// CompatibilityMetadata contains tanzu release support matrix
Expand Down
42 changes: 21 additions & 21 deletions pkg/v2/tkr/controller/tkr-source/compatibility/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/go-logr/logr"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -22,18 +21,27 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/yaml"

runv1 "github.com/vmware-tanzu/tanzu-framework/apis/run/v1alpha3"
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkr/pkg/constants"
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkr/pkg/types"
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/util/patchset"
"github.com/vmware-tanzu/tanzu-framework/pkg/v2/tkr/util/sets"
"github.com/vmware-tanzu/tanzu-framework/pkg/v2/tkr/util/version"
)

type Reconciler struct {
version.Compatibility

Ctx context.Context
Log logr.Logger
Client client.Client
Config Config
}

type Compatibility struct {
Client client.Client
Config Config
}

Expand Down Expand Up @@ -112,51 +120,43 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ct
}

func (r *Reconciler) updateTKRCompatibleCondition(ctx context.Context, tkr *runv1.TanzuKubernetesRelease) error {
compatibleSet, err := r.getCompatibleSet(ctx)
compatibleSet, err := r.CompatibleVersions(ctx)
if err != nil {
return err
}

if _, isCompatible := compatibleSet[tkr.Spec.Version]; isCompatible {
if compatibleSet.Has(tkr.Spec.Version) {
conditions.MarkTrue(tkr, runv1.ConditionCompatible)
return nil
}
conditions.MarkFalse(tkr, runv1.ConditionCompatible, "", clusterv1.ConditionSeverityWarning, "")
return nil
}

func (r *Reconciler) getCompatibleSet(ctx context.Context) (map[string]struct{}, error) {
mgmtClusterVersion, err := r.getManagementClusterVersion(ctx)
func (c *Compatibility) CompatibleVersions(ctx context.Context) (sets.StringSet, error) {
mgmtClusterVersion, err := c.getManagementClusterVersion(ctx)
if err != nil {
return nil, errors.Wrap(err, "failed to get the management cluster info")
}

metadata, err := r.compatibilityMetadata(ctx)
metadata, err := c.compatibilityMetadata(ctx)
if err != nil {
return nil, errors.Wrapf(err, "failed to get BOM compatibility metadata")
}

for _, mgmtVersion := range metadata.ManagementClusterVersions {
if mgmtClusterVersion == mgmtVersion.TKGVersion {
return stringSet(mgmtVersion.SupportedKubernetesVersions), nil
return sets.Strings(mgmtVersion.SupportedKubernetesVersions...), nil
}
}

return stringSet(nil), nil
}

func stringSet(ss []string) map[string]struct{} {
result := make(map[string]struct{}, len(ss))
for _, s := range ss {
result[s] = struct{}{}
}
return result
return sets.Strings(), nil
}

// getManagementClusterVersion get the version of the management cluster
func (r *Reconciler) getManagementClusterVersion(ctx context.Context) (string, error) {
func (c *Compatibility) getManagementClusterVersion(ctx context.Context) (string, error) {
clusterList := &clusterv1.ClusterList{}
if err := r.Client.List(ctx, clusterList, client.HasLabels{constants.ManagementClusterRoleLabel}); err != nil {
if err := c.Client.List(ctx, clusterList, client.HasLabels{constants.ManagementClusterRoleLabel}); err != nil {
return "", errors.Wrap(err, "failed to list clusters")
}

Expand All @@ -169,10 +169,10 @@ func (r *Reconciler) getManagementClusterVersion(ctx context.Context) (string, e
return "", errors.New("failed to get management cluster info")
}

func (r *Reconciler) compatibilityMetadata(ctx context.Context) (*types.CompatibilityMetadata, error) {
func (c *Compatibility) compatibilityMetadata(ctx context.Context) (*types.CompatibilityMetadata, error) {
cm := &corev1.ConfigMap{}
cmObjectKey := client.ObjectKey{Namespace: r.Config.TKRNamespace, Name: constants.BOMMetadataConfigMapName}
if err := r.Client.Get(ctx, cmObjectKey, cm); err != nil {
cmObjectKey := client.ObjectKey{Namespace: c.Config.TKRNamespace, Name: constants.BOMMetadataConfigMapName}
if err := c.Client.Get(ctx, cmObjectKey, cm); err != nil {
return nil, err
}

Expand Down
76 changes: 0 additions & 76 deletions pkg/v2/tkr/controller/tkr-source/fetcher/configurer.go

This file was deleted.

Loading

0 comments on commit 665627e

Please # to comment.