argo-cd/controller/clusterinfoupdater.go

182 lines
5.8 KiB
Go
Raw Permalink Normal View History

package controller
import (
"context"
chore: improve error logs (#10944) * fix: Resource list loading slowly due to Sync Wave sorting (#10932) Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: fix wrong annotation in function (#10923) Signed-off-by: wujunwei <wjw3323@live.com> Signed-off-by: wujunwei <wjw3323@live.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * feat: add bcrypt support for argocd CLI (#10934) * Adding bcrypt support for argocd CLI Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Fixing linter issues Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Nesting bcrypt under account instead of admin Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Removing admin bcrypt docs Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Update docs/faq.md Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Amey Totawar <ameytotawar@gmail.com> Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Signed-off-by: Amey Totawar <ameytotawar@gmail.com> Co-authored-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: improve error logs Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: improve error logs Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: implement signed images (#10925) * consolidate checksums into one file Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> * sign container images Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> * sign container images Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> * remove id-token permissions Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: delete old snyk reports (#10938) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: rewording of misleading message (#10407) Signed-off-by: Ryan Talbot <ryan-talbot@outlook.com> Signed-off-by: Ryan Talbot <ryan-talbot@outlook.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: delete old snyk reports, 2nd attempt (#10950) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: wrap error objects to include context (#10592) (#10940) Signed-off-by: Niharika <ns8gupta@gmail.com> Signed-off-by: Niharika <niharika_sahai@intuit.com> Signed-off-by: Niharika <ns8gupta@gmail.com> Signed-off-by: Niharika <niharika_sahai@intuit.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * fix: Use os.PathSeparator instead of hard-coded string to resolve local file paths (#10945) (#10946) fix: Use os.PathSeparator instead of hard-coded string to resolve local file paths (#10945) (#10946) Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: improve error logs Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: covered error log in controllers Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: sign checksums file for release binaries (#10963) Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * [Bot] Update Snyk reports (#10953) Signed-off-by: CI <ci@argoproj.com> Signed-off-by: CI <ci@argoproj.com> Co-authored-by: CI <ci@argoproj.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * feat: make applicationset controller configurable in argocd-cmd-params (#10961) Signed-off-by: toVersus <toversus2357@gmail.com> Signed-off-by: toVersus <toversus2357@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * docs: message is no longer truncated (#10962) Signed-off-by: Shawn Toffel <shawn.toffel@gmail.com> Signed-off-by: Shawn Toffel <shawn.toffel@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * fix: addressed review comments Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> Signed-off-by: wujunwei <wjw3323@live.com> Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Signed-off-by: Amey Totawar <ameytotawar@gmail.com> Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Ryan Talbot <ryan-talbot@outlook.com> Signed-off-by: Niharika <ns8gupta@gmail.com> Signed-off-by: Niharika <niharika_sahai@intuit.com> Signed-off-by: CI <ci@argoproj.com> Signed-off-by: toVersus <toversus2357@gmail.com> Signed-off-by: Shawn Toffel <shawn.toffel@gmail.com> Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Co-authored-by: Adam <wjw3323@live.com> Co-authored-by: Amey Totawar <ameytotawar@gmail.com> Co-authored-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Smriti Prakash <smriti_prakash@intuit.com> Co-authored-by: 34FathomBelow <34fathombelow@protonmail.com> Co-authored-by: Ryan Talbot <4523072+RyanTalbot@users.noreply.github.com> Co-authored-by: nsahai8 <ns8gupta@gmail.com> Co-authored-by: Chris Davis <chris@codeflow.org.uk> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: CI <ci@argoproj.com> Co-authored-by: Tsubasa Nagasawa <toversus2357@gmail.com> Co-authored-by: Shawn Toffel <shawn.toffel+github@gmail.com>
2022-10-18 15:16:20 +00:00
"fmt"
"time"
"github.com/argoproj/argo-cd/v3/common"
"github.com/argoproj/argo-cd/gitops-engine/pkg/cache"
"github.com/argoproj/argo-cd/gitops-engine/pkg/utils/kube"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"github.com/argoproj/argo-cd/v3/util/env"
"github.com/argoproj/argo-cd/v3/controller/metrics"
appv1 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1"
"github.com/argoproj/argo-cd/v3/pkg/client/listers/application/v1alpha1"
"github.com/argoproj/argo-cd/v3/util/argo"
appstatecache "github.com/argoproj/argo-cd/v3/util/cache/appstate"
"github.com/argoproj/argo-cd/v3/util/db"
)
const (
defaultSecretUpdateInterval = 10 * time.Second
EnvClusterInfoTimeout = "ARGO_CD_UPDATE_CLUSTER_INFO_TIMEOUT"
)
var clusterInfoTimeout = env.ParseDurationFromEnv(EnvClusterInfoTimeout, defaultSecretUpdateInterval, defaultSecretUpdateInterval, 1*time.Minute)
type clusterInfoUpdater struct {
infoSource metrics.HasClustersInfo
db db.ArgoDB
appLister v1alpha1.ApplicationNamespaceLister
cache *appstatecache.Cache
clusterFilter func(cluster *appv1.Cluster) bool
feat: Applications in any namespace (#9755) * feat: Applications in any namespace Signed-off-by: jannfis <jann@mistrust.net> * Fix typo in CI Signed-off-by: jannfis <jann@mistrust.net> * Create argocd-e2e-external namespace Signed-off-by: jannfis <jann@mistrust.net> * Update from codegen Signed-off-by: jannfis <jann@mistrust.net> * Remove debug code Signed-off-by: jannfis <jann@mistrust.net> * Update help text for -N option to app create Signed-off-by: jannfis <jann@mistrust.net> * Wrap error when retrieving AppProject from cache Signed-off-by: jannfis <jann@mistrust.net> * Check for controller namespace first before matching on additional ns Signed-off-by: jannfis <jann@mistrust.net> * Improve TestAppProjectIsSourceNamespacePermitted unit test Signed-off-by: jannfis <jann@mistrust.net> * Get rid of some debug leftovers Signed-off-by: jannfis <jann@mistrust.net> * Better error wrapping; return IsNotFound as-is Signed-off-by: jannfis <jann@mistrust.net> * Updates from codegen Signed-off-by: jannfis <jann@mistrust.net> * We don't need AppShortName() anymore Signed-off-by: jannfis <jann@mistrust.net> * Update end-to-end tests to use annotation methods Signed-off-by: jannfis <jann@mistrust.net> * Add e2e tests to test for app creation in not permitted ns Signed-off-by: jannfis <jann@mistrust.net> * Remove deprecated code Signed-off-by: jannfis <jann@mistrust.net> * Remove dead code Signed-off-by: jannfis <jann@mistrust.net> * Add RBACName() method to application type Signed-off-by: jannfis <jann@mistrust.net> * Update from codegen Signed-off-by: jannfis <jann@mistrust.net> * Fix e2e test Signed-off-by: jannfis <jann@mistrust.net> * Update codegen Signed-off-by: jannfis <jann@mistrust.net> * Move RBAC name generation to an application receiver Signed-off-by: jannfis <jann@mistrust.net> * Fix sync window status in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix pod logs viewer Signed-off-by: jannfis <jann@mistrust.net> * Fix application events in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix application search in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix yarn lint Signed-off-by: jannfis <jann@mistrust.net> * Only set up cluster-wide application informer when additional namespaces are specified Signed-off-by: jannfis <jann@mistrust.net> * Adapt e2e test to a changed error message Signed-off-by: jannfis <jann@mistrust.net> * Application namespace should be taken into account for create Signed-off-by: jannfis <jann@mistrust.net> * Use non-qualified application name as Helm release name Signed-off-by: jannfis <jann@mistrust.net> * Support --app-namespace in e2e tests Signed-off-by: jannfis <jann@mistrust.net> * Enable more e2e tests Signed-off-by: jannfis <jann@mistrust.net> * Increase e2e timeout for newly added tests Signed-off-by: jannfis <jann@mistrust.net>
2022-08-10 09:39:10 +00:00
projGetter func(app *appv1.Application) (*appv1.AppProject, error)
namespace string
lastUpdated time.Time
}
func NewClusterInfoUpdater(
infoSource metrics.HasClustersInfo,
db db.ArgoDB,
appLister v1alpha1.ApplicationNamespaceLister,
cache *appstatecache.Cache,
feat: Applications in any namespace (#9755) * feat: Applications in any namespace Signed-off-by: jannfis <jann@mistrust.net> * Fix typo in CI Signed-off-by: jannfis <jann@mistrust.net> * Create argocd-e2e-external namespace Signed-off-by: jannfis <jann@mistrust.net> * Update from codegen Signed-off-by: jannfis <jann@mistrust.net> * Remove debug code Signed-off-by: jannfis <jann@mistrust.net> * Update help text for -N option to app create Signed-off-by: jannfis <jann@mistrust.net> * Wrap error when retrieving AppProject from cache Signed-off-by: jannfis <jann@mistrust.net> * Check for controller namespace first before matching on additional ns Signed-off-by: jannfis <jann@mistrust.net> * Improve TestAppProjectIsSourceNamespacePermitted unit test Signed-off-by: jannfis <jann@mistrust.net> * Get rid of some debug leftovers Signed-off-by: jannfis <jann@mistrust.net> * Better error wrapping; return IsNotFound as-is Signed-off-by: jannfis <jann@mistrust.net> * Updates from codegen Signed-off-by: jannfis <jann@mistrust.net> * We don't need AppShortName() anymore Signed-off-by: jannfis <jann@mistrust.net> * Update end-to-end tests to use annotation methods Signed-off-by: jannfis <jann@mistrust.net> * Add e2e tests to test for app creation in not permitted ns Signed-off-by: jannfis <jann@mistrust.net> * Remove deprecated code Signed-off-by: jannfis <jann@mistrust.net> * Remove dead code Signed-off-by: jannfis <jann@mistrust.net> * Add RBACName() method to application type Signed-off-by: jannfis <jann@mistrust.net> * Update from codegen Signed-off-by: jannfis <jann@mistrust.net> * Fix e2e test Signed-off-by: jannfis <jann@mistrust.net> * Update codegen Signed-off-by: jannfis <jann@mistrust.net> * Move RBAC name generation to an application receiver Signed-off-by: jannfis <jann@mistrust.net> * Fix sync window status in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix pod logs viewer Signed-off-by: jannfis <jann@mistrust.net> * Fix application events in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix application search in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix yarn lint Signed-off-by: jannfis <jann@mistrust.net> * Only set up cluster-wide application informer when additional namespaces are specified Signed-off-by: jannfis <jann@mistrust.net> * Adapt e2e test to a changed error message Signed-off-by: jannfis <jann@mistrust.net> * Application namespace should be taken into account for create Signed-off-by: jannfis <jann@mistrust.net> * Use non-qualified application name as Helm release name Signed-off-by: jannfis <jann@mistrust.net> * Support --app-namespace in e2e tests Signed-off-by: jannfis <jann@mistrust.net> * Enable more e2e tests Signed-off-by: jannfis <jann@mistrust.net> * Increase e2e timeout for newly added tests Signed-off-by: jannfis <jann@mistrust.net>
2022-08-10 09:39:10 +00:00
clusterFilter func(cluster *appv1.Cluster) bool,
projGetter func(app *appv1.Application) (*appv1.AppProject, error),
namespace string,
) *clusterInfoUpdater {
return &clusterInfoUpdater{infoSource, db, appLister, cache, clusterFilter, projGetter, namespace, time.Time{}}
}
func (c *clusterInfoUpdater) Run(ctx context.Context) {
c.updateClusters()
ticker := time.NewTicker(clusterInfoTimeout)
for {
select {
case <-ctx.Done():
ticker.Stop()
return
case <-ticker.C:
c.updateClusters()
}
}
}
func (c *clusterInfoUpdater) updateClusters() {
if time.Since(c.lastUpdated) < clusterInfoTimeout {
return
}
ctx, cancel := context.WithTimeout(context.Background(), clusterInfoTimeout)
defer func() {
cancel()
c.lastUpdated = time.Now()
}()
infoByServer := make(map[string]*cache.ClusterInfo)
clustersInfo := c.infoSource.GetClustersInfo()
for i := range clustersInfo {
info := clustersInfo[i]
infoByServer[info.Server] = &info
}
clusters, err := c.db.ListClusters(ctx)
if err != nil {
log.Warnf("Failed to save clusters info: %v", err)
return
}
var clustersFiltered []appv1.Cluster
if c.clusterFilter == nil {
clustersFiltered = clusters.Items
} else {
for i := range clusters.Items {
if c.clusterFilter(&clusters.Items[i]) {
clustersFiltered = append(clustersFiltered, clusters.Items[i])
}
}
}
_ = kube.RunAllAsync(len(clustersFiltered), func(i int) error {
cluster := clustersFiltered[i]
clusterInfo := infoByServer[cluster.Server]
if err := c.updateClusterInfo(ctx, cluster, clusterInfo); err != nil {
log.Warnf("Failed to save cluster info: %v", err)
} else if err := updateClusterLabels(ctx, clusterInfo, cluster, c.db.UpdateCluster); err != nil {
log.Warnf("Failed to update cluster labels: %v", err)
}
return nil
})
log.Debugf("Successfully saved info of %d clusters", len(clustersFiltered))
}
func (c *clusterInfoUpdater) updateClusterInfo(ctx context.Context, cluster appv1.Cluster, info *cache.ClusterInfo) error {
apps, err := c.appLister.List(labels.Everything())
if err != nil {
chore: improve error logs (#10944) * fix: Resource list loading slowly due to Sync Wave sorting (#10932) Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: fix wrong annotation in function (#10923) Signed-off-by: wujunwei <wjw3323@live.com> Signed-off-by: wujunwei <wjw3323@live.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * feat: add bcrypt support for argocd CLI (#10934) * Adding bcrypt support for argocd CLI Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Fixing linter issues Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Nesting bcrypt under account instead of admin Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Removing admin bcrypt docs Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> * Update docs/faq.md Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Amey Totawar <ameytotawar@gmail.com> Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Signed-off-by: Amey Totawar <ameytotawar@gmail.com> Co-authored-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: improve error logs Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: improve error logs Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: implement signed images (#10925) * consolidate checksums into one file Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> * sign container images Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> * sign container images Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> * remove id-token permissions Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: delete old snyk reports (#10938) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: rewording of misleading message (#10407) Signed-off-by: Ryan Talbot <ryan-talbot@outlook.com> Signed-off-by: Ryan Talbot <ryan-talbot@outlook.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: delete old snyk reports, 2nd attempt (#10950) Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: wrap error objects to include context (#10592) (#10940) Signed-off-by: Niharika <ns8gupta@gmail.com> Signed-off-by: Niharika <niharika_sahai@intuit.com> Signed-off-by: Niharika <ns8gupta@gmail.com> Signed-off-by: Niharika <niharika_sahai@intuit.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * fix: Use os.PathSeparator instead of hard-coded string to resolve local file paths (#10945) (#10946) fix: Use os.PathSeparator instead of hard-coded string to resolve local file paths (#10945) (#10946) Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: improve error logs Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: covered error log in controllers Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * chore: sign checksums file for release binaries (#10963) Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * [Bot] Update Snyk reports (#10953) Signed-off-by: CI <ci@argoproj.com> Signed-off-by: CI <ci@argoproj.com> Co-authored-by: CI <ci@argoproj.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * feat: make applicationset controller configurable in argocd-cmd-params (#10961) Signed-off-by: toVersus <toversus2357@gmail.com> Signed-off-by: toVersus <toversus2357@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * docs: message is no longer truncated (#10962) Signed-off-by: Shawn Toffel <shawn.toffel@gmail.com> Signed-off-by: Shawn Toffel <shawn.toffel@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> * fix: addressed review comments Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Signed-off-by: Smriti Prakash <smriti_prakash@intuit.com> Signed-off-by: wujunwei <wjw3323@live.com> Signed-off-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Signed-off-by: Amey Totawar <ameytotawar@gmail.com> Signed-off-by: Justin Marquis <34fathombelow@protonmail.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Signed-off-by: Ryan Talbot <ryan-talbot@outlook.com> Signed-off-by: Niharika <ns8gupta@gmail.com> Signed-off-by: Niharika <niharika_sahai@intuit.com> Signed-off-by: CI <ci@argoproj.com> Signed-off-by: toVersus <toversus2357@gmail.com> Signed-off-by: Shawn Toffel <shawn.toffel@gmail.com> Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Co-authored-by: Adam <wjw3323@live.com> Co-authored-by: Amey Totawar <ameytotawar@gmail.com> Co-authored-by: Amey Totawar <ameysanjaykumar_totawar@intuit.com> Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Smriti Prakash <smriti_prakash@intuit.com> Co-authored-by: 34FathomBelow <34fathombelow@protonmail.com> Co-authored-by: Ryan Talbot <4523072+RyanTalbot@users.noreply.github.com> Co-authored-by: nsahai8 <ns8gupta@gmail.com> Co-authored-by: Chris Davis <chris@codeflow.org.uk> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: CI <ci@argoproj.com> Co-authored-by: Tsubasa Nagasawa <toversus2357@gmail.com> Co-authored-by: Shawn Toffel <shawn.toffel+github@gmail.com>
2022-10-18 15:16:20 +00:00
return fmt.Errorf("error while fetching the apps list: %w", err)
}
updated := c.getUpdatedClusterInfo(ctx, apps, cluster, info, metav1.Now())
return c.cache.SetClusterInfo(cluster.Server, &updated)
}
func (c *clusterInfoUpdater) getUpdatedClusterInfo(ctx context.Context, apps []*appv1.Application, cluster appv1.Cluster, info *cache.ClusterInfo, now metav1.Time) appv1.ClusterInfo {
var appCount int64
for _, a := range apps {
feat: Applications in any namespace (#9755) * feat: Applications in any namespace Signed-off-by: jannfis <jann@mistrust.net> * Fix typo in CI Signed-off-by: jannfis <jann@mistrust.net> * Create argocd-e2e-external namespace Signed-off-by: jannfis <jann@mistrust.net> * Update from codegen Signed-off-by: jannfis <jann@mistrust.net> * Remove debug code Signed-off-by: jannfis <jann@mistrust.net> * Update help text for -N option to app create Signed-off-by: jannfis <jann@mistrust.net> * Wrap error when retrieving AppProject from cache Signed-off-by: jannfis <jann@mistrust.net> * Check for controller namespace first before matching on additional ns Signed-off-by: jannfis <jann@mistrust.net> * Improve TestAppProjectIsSourceNamespacePermitted unit test Signed-off-by: jannfis <jann@mistrust.net> * Get rid of some debug leftovers Signed-off-by: jannfis <jann@mistrust.net> * Better error wrapping; return IsNotFound as-is Signed-off-by: jannfis <jann@mistrust.net> * Updates from codegen Signed-off-by: jannfis <jann@mistrust.net> * We don't need AppShortName() anymore Signed-off-by: jannfis <jann@mistrust.net> * Update end-to-end tests to use annotation methods Signed-off-by: jannfis <jann@mistrust.net> * Add e2e tests to test for app creation in not permitted ns Signed-off-by: jannfis <jann@mistrust.net> * Remove deprecated code Signed-off-by: jannfis <jann@mistrust.net> * Remove dead code Signed-off-by: jannfis <jann@mistrust.net> * Add RBACName() method to application type Signed-off-by: jannfis <jann@mistrust.net> * Update from codegen Signed-off-by: jannfis <jann@mistrust.net> * Fix e2e test Signed-off-by: jannfis <jann@mistrust.net> * Update codegen Signed-off-by: jannfis <jann@mistrust.net> * Move RBAC name generation to an application receiver Signed-off-by: jannfis <jann@mistrust.net> * Fix sync window status in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix pod logs viewer Signed-off-by: jannfis <jann@mistrust.net> * Fix application events in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix application search in UI Signed-off-by: jannfis <jann@mistrust.net> * Fix yarn lint Signed-off-by: jannfis <jann@mistrust.net> * Only set up cluster-wide application informer when additional namespaces are specified Signed-off-by: jannfis <jann@mistrust.net> * Adapt e2e test to a changed error message Signed-off-by: jannfis <jann@mistrust.net> * Application namespace should be taken into account for create Signed-off-by: jannfis <jann@mistrust.net> * Use non-qualified application name as Helm release name Signed-off-by: jannfis <jann@mistrust.net> * Support --app-namespace in e2e tests Signed-off-by: jannfis <jann@mistrust.net> * Enable more e2e tests Signed-off-by: jannfis <jann@mistrust.net> * Increase e2e timeout for newly added tests Signed-off-by: jannfis <jann@mistrust.net>
2022-08-10 09:39:10 +00:00
if c.projGetter != nil {
proj, err := c.projGetter(a)
if err != nil || !proj.IsAppNamespacePermitted(a, c.namespace) {
continue
}
}
destServer, err := argo.GetDestinationServer(ctx, a.Spec.Destination, c.db)
if err != nil {
continue
}
if destServer == cluster.Server {
appCount++
}
}
clusterInfo := appv1.ClusterInfo{
ConnectionState: appv1.ConnectionState{ModifiedAt: &now},
ApplicationsCount: appCount,
}
if info != nil {
clusterInfo.ServerVersion = info.K8SVersion
clusterInfo.APIVersions = argo.APIResourcesToStrings(info.APIResources, true)
switch {
case info.LastCacheSyncTime == nil:
clusterInfo.ConnectionState.Status = appv1.ConnectionStatusUnknown
case info.SyncError == nil:
clusterInfo.ConnectionState.Status = appv1.ConnectionStatusSuccessful
syncTime := metav1.NewTime(*info.LastCacheSyncTime)
clusterInfo.CacheInfo.LastCacheSyncTime = &syncTime
clusterInfo.CacheInfo.APIsCount = int64(info.APIsCount)
clusterInfo.CacheInfo.ResourcesCount = int64(info.ResourcesCount)
default:
clusterInfo.ConnectionState.Status = appv1.ConnectionStatusFailed
clusterInfo.ConnectionState.Message = info.SyncError.Error()
}
} else {
clusterInfo.ConnectionState.Status = appv1.ConnectionStatusUnknown
if appCount == 0 {
clusterInfo.ConnectionState.Message = "Cluster has no applications and is not being monitored."
}
}
return clusterInfo
}
func updateClusterLabels(ctx context.Context, clusterInfo *cache.ClusterInfo, cluster appv1.Cluster, updateCluster func(context.Context, *appv1.Cluster) (*appv1.Cluster, error)) error {
if clusterInfo != nil && cluster.Labels[common.LabelKeyAutoLabelClusterInfo] == "true" && cluster.Labels[common.LabelKeyClusterKubernetesVersion] != clusterInfo.K8SVersion {
cluster.Labels[common.LabelKeyClusterKubernetesVersion] = clusterInfo.K8SVersion
_, err := updateCluster(ctx, &cluster)
return err
}
return nil
}