Skip to content

Commit 8130b6e

Browse files
committed
Remove deprecated auto-login flags
The auto-login controller flags (--aws-autologin-for-ecr, --gcp-autologin-for-gcr, --azure-autologin-for-acr) have been deprecated since v0.25.0 and replaced by the .spec.provider field. This change removes these flags entirely. Also removes the unsupported provider check as it's now handled by the updated fluxcd/pkg/auth package. Signed-off-by: cappyzawa <[email protected]>
1 parent dcbcab1 commit 8130b6e

File tree

4 files changed

+28
-67
lines changed

4 files changed

+28
-67
lines changed

internal/controller/imagerepository_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ type ImageRepositoryReconciler struct {
111111
DatabaseWriter
112112
DatabaseReader
113113
}
114-
DeprecatedLoginOpts []auth.Provider
115-
AuthOptionsGetter *registry.AuthOptionsGetter
114+
AuthOptionsGetter *registry.AuthOptionsGetter
116115

117116
patchOptions []patch.Option
118117
}
@@ -270,7 +269,7 @@ func (r *ImageRepositoryReconciler) reconcile(ctx context.Context, sp *patch.Ser
270269
Namespace: obj.GetNamespace(),
271270
Operation: cache.OperationReconcile,
272271
}
273-
opts, err := r.AuthOptionsGetter.GetOptions(ctx, obj, involvedObject, r.DeprecatedLoginOpts...)
272+
opts, err := r.AuthOptionsGetter.GetOptions(ctx, obj, involvedObject)
274273
if err != nil {
275274
e := fmt.Errorf("failed to configure authentication options: %w", err)
276275
conditions.MarkFalse(obj, meta.ReadyCondition, imagev1.AuthenticationFailedReason, "%s", e)

internal/registry/options.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/client"
3232

3333
"github.com/fluxcd/pkg/auth"
34-
"github.com/fluxcd/pkg/auth/aws"
35-
"github.com/fluxcd/pkg/auth/azure"
36-
"github.com/fluxcd/pkg/auth/gcp"
3734
authutils "github.com/fluxcd/pkg/auth/utils"
3835
"github.com/fluxcd/pkg/cache"
3936

@@ -57,7 +54,7 @@ type AuthOptionsGetter struct {
5754
}
5855

5956
func (r *AuthOptionsGetter) GetOptions(ctx context.Context, repo *imagev1.ImageRepository,
60-
involvedObject *cache.InvolvedObject, deprecatedLoginOpts ...auth.Provider) ([]remote.Option, error) {
57+
involvedObject *cache.InvolvedObject) ([]remote.Option, error) {
6158
timeout := repo.GetTimeout()
6259
ctx, cancel := context.WithTimeout(ctx, timeout)
6360
defer cancel()
@@ -98,36 +95,23 @@ func (r *AuthOptionsGetter) GetOptions(ctx context.Context, repo *imagev1.ImageR
9895
return nil, err
9996
}
10097
authenticator, authErr = secret.AuthFromSecret(authSecret, ref)
101-
} else {
98+
} else if provider := repo.GetProvider(); provider != "generic" {
10299
// Build login provider options and use it to attempt registry login.
103100
var opts []auth.Option
104101
if proxyURL != nil {
105102
opts = append(opts, auth.WithProxyURL(*proxyURL))
106103
}
107-
switch provider := repo.GetProvider(); provider {
108-
case aws.ProviderName, azure.ProviderName, gcp.ProviderName:
109-
// Support new features (service account and cache) only for non-deprecated code paths.
110-
if repo.Spec.ServiceAccountName != "" {
111-
serviceAccount := client.ObjectKey{
112-
Name: repo.Spec.ServiceAccountName,
113-
Namespace: repo.GetNamespace(),
114-
}
115-
opts = append(opts, auth.WithServiceAccount(serviceAccount, r.Client))
116-
}
117-
if r.TokenCache != nil {
118-
opts = append(opts, auth.WithCache(*r.TokenCache, *involvedObject))
119-
}
120-
authenticator, authErr = authutils.GetArtifactRegistryCredentials(ctx, provider, repo.Spec.Image, opts...)
121-
default:
122-
// Handle deprecated auto-login controller flags.
123-
for _, provider := range deprecatedLoginOpts {
124-
if _, err := provider.ParseArtifactRepository(repo.Spec.Image); err == nil {
125-
authenticator, authErr = authutils.GetArtifactRegistryCredentials(ctx,
126-
provider.GetName(), repo.Spec.Image, opts...)
127-
break
128-
}
104+
if repo.Spec.ServiceAccountName != "" {
105+
serviceAccount := client.ObjectKey{
106+
Name: repo.Spec.ServiceAccountName,
107+
Namespace: repo.GetNamespace(),
129108
}
109+
opts = append(opts, auth.WithServiceAccount(serviceAccount, r.Client))
110+
}
111+
if r.TokenCache != nil {
112+
opts = append(opts, auth.WithCache(*r.TokenCache, *involvedObject))
130113
}
114+
authenticator, authErr = authutils.GetArtifactRegistryCredentials(ctx, provider, repo.Spec.Image, opts...)
131115
}
132116
if authErr != nil {
133117
return nil, authErr

internal/registry/options_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ func TestNewAuthOptionsGetter_GetOptions(t *testing.T) {
260260
},
261261
wantErr: true,
262262
},
263+
{
264+
name: "unsupported provider",
265+
imageRepoSpec: imagev1.ImageRepositorySpec{
266+
Image: testImg,
267+
Provider: "unsupported-provider",
268+
},
269+
wantErr: true,
270+
},
263271
}
264272

265273
for _, tt := range tests {

main.go

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"errors"
2120
"fmt"
2221
"os"
2322
"time"
@@ -38,9 +37,6 @@ import (
3837
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3938

4039
"github.com/fluxcd/pkg/auth"
41-
"github.com/fluxcd/pkg/auth/aws"
42-
"github.com/fluxcd/pkg/auth/azure"
43-
"github.com/fluxcd/pkg/auth/gcp"
4440
pkgcache "github.com/fluxcd/pkg/cache"
4541
"github.com/fluxcd/pkg/runtime/acl"
4642
"github.com/fluxcd/pkg/runtime/client"
@@ -96,9 +92,6 @@ func main() {
9692
storageValueLogFileSize int64
9793
gcInterval uint16 // max value is 65535 minutes (~ 45 days) which is well under the maximum time.Duration
9894
concurrent int
99-
awsAutoLogin bool
100-
gcpAutoLogin bool
101-
azureAutoLogin bool
10295
aclOptions acl.Options
10396
rateLimiterOptions helper.RateLimiterOptions
10497
featureGates feathelper.FeatureGates
@@ -113,11 +106,6 @@ func main() {
113106
flag.Uint16Var(&gcInterval, "gc-interval", 10, "The number of minutes to wait between garbage collections. 0 disables the garbage collector.")
114107
flag.IntVar(&concurrent, "concurrent", 4, "The number of concurrent resource reconciles.")
115108

116-
// NOTE: Deprecated flags.
117-
flag.BoolVar(&awsAutoLogin, "aws-autologin-for-ecr", false, "(AWS) Attempt to get credentials for images in Elastic Container Registry, when no secret is referenced")
118-
flag.BoolVar(&gcpAutoLogin, "gcp-autologin-for-gcr", false, "(GCP) Attempt to get credentials for images in Google Container Registry, when no secret is referenced")
119-
flag.BoolVar(&azureAutoLogin, "azure-autologin-for-acr", false, "(Azure) Attempt to get credentials for images in Azure Container Registry, when no secret is referenced")
120-
121109
clientOptions.BindFlags(flag.CommandLine)
122110
logOptions.BindFlags(flag.CommandLine)
123111
leaderElectionOptions.BindFlags(flag.CommandLine)
@@ -131,12 +119,6 @@ func main() {
131119

132120
logger.SetLogger(logger.NewLogger(logOptions))
133121

134-
if awsAutoLogin || gcpAutoLogin || azureAutoLogin {
135-
setupLog.Error(errors.New("use of deprecated flags"),
136-
"autologin flags have been deprecated. These flags will be removed in a future release."+
137-
" Please update the respective ImageRepository objects with .spec.provider field.")
138-
}
139-
140122
if err := featureGates.WithLogger(setupLog).SupportedFeatures(features.FeatureGates()); err != nil {
141123
setupLog.Error(err, "unable to load feature gates")
142124
os.Exit(1)
@@ -265,31 +247,19 @@ func main() {
265247
}
266248
}
267249

268-
var deprecatedLoginOpts []auth.Provider
269-
if awsAutoLogin {
270-
deprecatedLoginOpts = append(deprecatedLoginOpts, aws.Provider{})
271-
}
272-
if azureAutoLogin {
273-
deprecatedLoginOpts = append(deprecatedLoginOpts, azure.Provider{})
274-
}
275-
if gcpAutoLogin {
276-
deprecatedLoginOpts = append(deprecatedLoginOpts, gcp.Provider{})
277-
}
278-
279250
authOptionsGetter := &registry.AuthOptionsGetter{
280251
Client: mgr.GetClient(),
281252
TokenCache: tokenCache,
282253
}
283254

284255
if err := (&controller.ImageRepositoryReconciler{
285-
Client: mgr.GetClient(),
286-
EventRecorder: eventRecorder,
287-
Metrics: metricsH,
288-
Database: db,
289-
ControllerName: controllerName,
290-
TokenCache: tokenCache,
291-
AuthOptionsGetter: authOptionsGetter,
292-
DeprecatedLoginOpts: deprecatedLoginOpts,
256+
Client: mgr.GetClient(),
257+
EventRecorder: eventRecorder,
258+
Metrics: metricsH,
259+
Database: db,
260+
ControllerName: controllerName,
261+
TokenCache: tokenCache,
262+
AuthOptionsGetter: authOptionsGetter,
293263
}).SetupWithManager(mgr, controller.ImageRepositoryReconcilerOptions{
294264
RateLimiter: helper.GetRateLimiter(rateLimiterOptions),
295265
}); err != nil {

0 commit comments

Comments
 (0)