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

Pass additional information to downward API (k8s version, kc version, k8s g/v) #846

Merged
merged 8 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
27 changes: 15 additions & 12 deletions cmd/controller/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
pkgclient "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apiserver/client/clientset/versioned"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/app"
kcclient "github.com/vmware-tanzu/carvel-kapp-controller/pkg/client/clientset/versioned"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/componentinfo"
kcconfig "github.com/vmware-tanzu/carvel-kapp-controller/pkg/config"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/deploy"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/exec"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/kubeconfig"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/metrics"
pkginstall "github.com/vmware-tanzu/carvel-kapp-controller/pkg/packageinstall"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/pkgrepository"
Expand Down Expand Up @@ -170,20 +171,22 @@ func Run(opts Options, runLog logr.Logger) error {
refTracker := reftracker.NewAppRefTracker()
updateStatusTracker := reftracker.NewAppUpdateStatus()

// initialize deploy factory once - the deploy factory contains a service account token cache which should be only setup once.
deployFactory := deploy.NewFactory(coreClient, kcConfig, sidecarCmdExec, runLog)
// initialize cluster access once - it contains a service account token cache which should be only setup once.
kubeconf := kubeconfig.NewKubeconfig(coreClient, runLog)
compInfo := componentinfo.NewComponentInfo(coreClient, kubeconf, Version)

{ // add controller for apps
appFactory := app.CRDAppFactory{
CoreClient: coreClient,
AppClient: kcClient,
KcConfig: kcConfig,
AppMetrics: appMetrics,
CmdRunner: sidecarCmdExec,
DeployFactory: deployFactory,
CoreClient: coreClient,
AppClient: kcClient,
KcConfig: kcConfig,
AppMetrics: appMetrics,
CmdRunner: sidecarCmdExec,
Kubeconf: kubeconf,
CompInfo: compInfo,
}
reconciler := app.NewReconciler(kcClient, runLog.WithName("app"),
appFactory, refTracker, updateStatusTracker)
appFactory, refTracker, updateStatusTracker, compInfo)

ctrl, err := controller.New("app", mgr, controller.Options{
Reconciler: NewUniqueReconciler(&ErrReconciler{
Expand All @@ -206,7 +209,7 @@ func Run(opts Options, runLog logr.Logger) error {
pkgToPkgInstallHandler := pkginstall.NewPackageInstallVersionHandler(
kcClient, opts.PackagingGloablNS, runLog.WithName("handler"))

reconciler := pkginstall.NewReconciler(deployFactory, kcClient, pkgClient, coreClient, pkgToPkgInstallHandler, runLog.WithName("pkgi"), Version)
reconciler := pkginstall.NewReconciler(kcClient, pkgClient, coreClient, pkgToPkgInstallHandler, runLog.WithName("pkgi"), compInfo)

ctrl, err := controller.New("pkgi", mgr, controller.Options{
Reconciler: reconciler,
Expand All @@ -223,7 +226,7 @@ func Run(opts Options, runLog logr.Logger) error {
}

{ // add controller for pkgrepositories
appFactory := pkgrepository.AppFactory{coreClient, kcClient, kcConfig, sidecarCmdExec}
appFactory := pkgrepository.AppFactory{coreClient, kcClient, kcConfig, sidecarCmdExec, kubeconf}

reconciler := pkgrepository.NewReconciler(kcClient, coreClient,
runLog.WithName("pkgr"), appFactory, refTracker, updateStatusTracker)
Expand Down
144 changes: 144 additions & 0 deletions config/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,26 @@ spec:
fieldPath:
description: 'Required: Selects a field of the app: only annotations, labels, uid, name and namespace are supported.'
type: string
kappControllerVersion:
description: 'Optional: Get running KappController version, defaults (empty) to retrieving the current running version.. Can be manually supplied instead.'
properties:
version:
type: string
type: object
kubernetesAPIs:
description: 'Optional: Get running KubernetesAPIs from cluster, defaults (empty) to retrieving the APIs from the cluster. Can be manually supplied instead, e.g ["group/version", "group2/version2"]'
properties:
groupVersions:
items:
type: string
type: array
type: object
kubernetesVersion:
description: 'Optional: Get running Kubernetes version from cluster, defaults (empty) to retrieving the version from the cluster. Can be manually supplied instead.'
properties:
version:
type: string
type: object
name:
type: string
type: object
Expand All @@ -445,6 +465,18 @@ spec:
helmTemplate:
description: Use helm template command to render helm chart
properties:
kubernetesAPIs:
description: 'Optional: Use kubernetes group/versions resources available in the live cluster'
properties:
version:
type: string
type: object
kubernetesVersion:
description: 'Optional: Get Kubernetes version, defaults (empty) to retrieving the version from the cluster. Can be manually overridden to a value instead.'
properties:
version:
type: string
type: object
name:
description: Set name explicitly, default is App CR's name (optional; v0.13.0+)
type: string
Expand All @@ -471,6 +503,26 @@ spec:
fieldPath:
description: 'Required: Selects a field of the app: only annotations, labels, uid, name and namespace are supported.'
type: string
kappControllerVersion:
description: 'Optional: Get running KappController version, defaults (empty) to retrieving the current running version.. Can be manually supplied instead.'
properties:
version:
type: string
type: object
kubernetesAPIs:
description: 'Optional: Get running KubernetesAPIs from cluster, defaults (empty) to retrieving the APIs from the cluster. Can be manually supplied instead, e.g ["group/version", "group2/version2"]'
properties:
groupVersions:
items:
type: string
type: array
type: object
kubernetesVersion:
description: 'Optional: Get running Kubernetes version from cluster, defaults (empty) to retrieving the version from the cluster. Can be manually supplied instead.'
properties:
version:
type: string
type: object
name:
type: string
type: object
Expand Down Expand Up @@ -595,6 +647,26 @@ spec:
fieldPath:
description: 'Required: Selects a field of the app: only annotations, labels, uid, name and namespace are supported.'
type: string
kappControllerVersion:
description: 'Optional: Get running KappController version, defaults (empty) to retrieving the current running version.. Can be manually supplied instead.'
properties:
version:
type: string
type: object
kubernetesAPIs:
description: 'Optional: Get running KubernetesAPIs from cluster, defaults (empty) to retrieving the APIs from the cluster. Can be manually supplied instead, e.g ["group/version", "group2/version2"]'
properties:
groupVersions:
items:
type: string
type: array
type: object
kubernetesVersion:
description: 'Optional: Get running Kubernetes version from cluster, defaults (empty) to retrieving the version from the cluster. Can be manually supplied instead.'
properties:
version:
type: string
type: object
name:
type: string
type: object
Expand Down Expand Up @@ -966,6 +1038,26 @@ spec:
fieldPath:
description: 'Required: Selects a field of the app: only annotations, labels, uid, name and namespace are supported.'
type: string
kappControllerVersion:
description: 'Optional: Get running KappController version, defaults (empty) to retrieving the current running version.. Can be manually supplied instead.'
properties:
version:
type: string
type: object
kubernetesAPIs:
description: 'Optional: Get running KubernetesAPIs from cluster, defaults (empty) to retrieving the APIs from the cluster. Can be manually supplied instead, e.g ["group/version", "group2/version2"]'
properties:
groupVersions:
items:
type: string
type: array
type: object
kubernetesVersion:
description: 'Optional: Get running Kubernetes version from cluster, defaults (empty) to retrieving the version from the cluster. Can be manually supplied instead.'
properties:
version:
type: string
type: object
name:
type: string
type: object
Expand All @@ -984,6 +1076,18 @@ spec:
helmTemplate:
description: Use helm template command to render helm chart
properties:
kubernetesAPIs:
description: 'Optional: Use kubernetes group/versions resources available in the live cluster'
properties:
version:
type: string
type: object
kubernetesVersion:
description: 'Optional: Get Kubernetes version, defaults (empty) to retrieving the version from the cluster. Can be manually overridden to a value instead.'
properties:
version:
type: string
type: object
name:
description: Set name explicitly, default is App CR's name (optional; v0.13.0+)
type: string
Expand All @@ -1010,6 +1114,26 @@ spec:
fieldPath:
description: 'Required: Selects a field of the app: only annotations, labels, uid, name and namespace are supported.'
type: string
kappControllerVersion:
description: 'Optional: Get running KappController version, defaults (empty) to retrieving the current running version.. Can be manually supplied instead.'
properties:
version:
type: string
type: object
kubernetesAPIs:
description: 'Optional: Get running KubernetesAPIs from cluster, defaults (empty) to retrieving the APIs from the cluster. Can be manually supplied instead, e.g ["group/version", "group2/version2"]'
properties:
groupVersions:
items:
type: string
type: array
type: object
kubernetesVersion:
description: 'Optional: Get running Kubernetes version from cluster, defaults (empty) to retrieving the version from the cluster. Can be manually supplied instead.'
properties:
version:
type: string
type: object
name:
type: string
type: object
Expand Down Expand Up @@ -1134,6 +1258,26 @@ spec:
fieldPath:
description: 'Required: Selects a field of the app: only annotations, labels, uid, name and namespace are supported.'
type: string
kappControllerVersion:
description: 'Optional: Get running KappController version, defaults (empty) to retrieving the current running version.. Can be manually supplied instead.'
properties:
version:
type: string
type: object
kubernetesAPIs:
description: 'Optional: Get running KubernetesAPIs from cluster, defaults (empty) to retrieving the APIs from the cluster. Can be manually supplied instead, e.g ["group/version", "group2/version2"]'
properties:
groupVersions:
items:
type: string
type: array
type: object
kubernetesVersion:
description: 'Optional: Get running Kubernetes version from cluster, defaults (empty) to retrieving the version from the cluster. Can be manually supplied instead.'
properties:
version:
type: string
type: object
name:
type: string
type: object
Expand Down
Loading