From 15ab075826243ac01f56dfd134d32f49afe8c2ec Mon Sep 17 00:00:00 2001 From: Soule BA Date: Tue, 22 Mar 2022 09:15:55 +0100 Subject: [PATCH] Add MIT Licence copyright notice Signed-off-by: Soule BA --- api/v1beta2/condition_types.go | 1 + internal/cache/LICENSE | 19 +++++++++++++ internal/cache/cache.go | 29 ++++++++------------ main.go | 50 +++++++++++++++++----------------- 4 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 internal/cache/LICENSE diff --git a/api/v1beta2/condition_types.go b/api/v1beta2/condition_types.go index c22e2a15a..711469eb8 100644 --- a/api/v1beta2/condition_types.go +++ b/api/v1beta2/condition_types.go @@ -97,6 +97,7 @@ const ( // ArtifactUpToDateReason signals that an existing Artifact is up-to-date // with the Source. ArtifactUpToDateReason string = "ArtifactUpToDate" + // CacheOperationFailedReason signals a failure in cache operation. CacheOperationFailedReason string = "CacheOperationFailed" ) diff --git a/internal/cache/LICENSE b/internal/cache/LICENSE new file mode 100644 index 000000000..f49969d7f --- /dev/null +++ b/internal/cache/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012-2019 Patrick Mylund Nielsen and the go-cache contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/internal/cache/cache.go b/internal/cache/cache.go index a46793762..4673f4f2b 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -1,18 +1,14 @@ -/* -Copyright 2022 The Flux authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ +// Copyright (c) 2012-2019 Patrick Mylund Nielsen and the go-cache contributors +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// Copyright 2022 The FluxCD contributors. All rights reserved. +// This package provides an in-memory cache +// derived from the https://github.com/patrickmn/go-cache +// package +// It has been modified in order to keep a small set of functions +// and to add a maxItems parameter in order to limit the number of, +// and thus the size of, items in the cache. package cache @@ -23,9 +19,6 @@ import ( "time" ) -// NOTE: this is heavily based on patrickmn/go-cache: -// https://github.com/patrickmn/go-cache - // Cache is a thread-safe in-memory key/value store. type Cache struct { *cache diff --git a/main.go b/main.go index b6767eab5..e24298360 100644 --- a/main.go +++ b/main.go @@ -72,24 +72,24 @@ func init() { func main() { var ( - metricsAddr string - eventsAddr string - healthAddr string - storagePath string - storageAddr string - storageAdvAddr string - concurrent int - requeueDependency time.Duration - watchAllNamespaces bool - helmIndexLimit int64 - helmChartLimit int64 - helmChartFileLimit int64 - clientOptions client.Options - logOptions logger.Options - leaderElectionOptions leaderelection.Options - cacheMaxSize int - cacheTTL string - cachePurgeInterval string + metricsAddr string + eventsAddr string + healthAddr string + storagePath string + storageAddr string + storageAdvAddr string + concurrent int + requeueDependency time.Duration + watchAllNamespaces bool + helmIndexLimit int64 + helmChartLimit int64 + helmChartFileLimit int64 + clientOptions client.Options + logOptions logger.Options + leaderElectionOptions leaderelection.Options + helmCacheMaxSize int + helmCacheTTL string + helmCachePurgeInterval string ) flag.StringVar(&metricsAddr, "metrics-addr", envOrDefault("METRICS_ADDR", ":8080"), @@ -114,11 +114,11 @@ func main() { "The max allowed size in bytes of a file in a Helm chart.") flag.DurationVar(&requeueDependency, "requeue-dependency", 30*time.Second, "The interval at which failing dependencies are reevaluated.") - flag.IntVar(&cacheMaxSize, "cache-max-size", 0, + flag.IntVar(&helmCacheMaxSize, "helm-cache-max-size", 0, "The maximum size of the cache in number of items.") - flag.StringVar(&cacheTTL, "cache-ttl", "15m", + flag.StringVar(&helmCacheTTL, "helm-cache-ttl", "15m", "The TTL of an item in the cache. Valid time units are ns, us (or µs), ms, s, m, h.") - flag.StringVar(&cachePurgeInterval, "cache-purge-interval", "1m", + flag.StringVar(&helmCachePurgeInterval, "helm-cache-purge-interval", "1m", "The interval at which the cache is purged. Valid time units are ns, us (or µs), ms, s, m, h.") clientOptions.BindFlags(flag.CommandLine) @@ -204,20 +204,20 @@ func main() { var c *cache.Cache var ttl time.Duration - if cacheMaxSize > 0 { - interval, err := time.ParseDuration(cachePurgeInterval) + if helmCacheMaxSize > 0 { + interval, err := time.ParseDuration(helmCachePurgeInterval) if err != nil { setupLog.Error(err, "unable to parse cache purge interval") os.Exit(1) } - ttl, err = time.ParseDuration(cacheTTL) + ttl, err = time.ParseDuration(helmCacheTTL) if err != nil { setupLog.Error(err, "unable to parse cache TTL") os.Exit(1) } - c = cache.New(cacheMaxSize, interval) + c = cache.New(helmCacheMaxSize, interval) } if err = (&controllers.HelmChartReconciler{ Client: mgr.GetClient(),