Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshift#298 from sanchezl/disable-image-pull-sec…
…ret-generation API-1642: Do not generate image pull secrets for internal registry when internal registry is disabled.
- Loading branch information
Showing
105 changed files
with
1,134 additions
and
4,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package bindata | ||
|
||
import ( | ||
"embed" | ||
) | ||
|
||
//go:embed assets/* | ||
var f embed.FS | ||
|
||
// Asset reads and returns the content of the named file. | ||
func Asset(name string) ([]byte, error) { | ||
return f.ReadFile(name) | ||
} | ||
|
||
// MustAsset reads and returns the content of the named file or panics | ||
// if something went wrong. | ||
func MustAsset(name string) []byte { | ||
data, err := f.ReadFile(name) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return data | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
pkg/operator/configobservation/controllers/capability_builds.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package controllers | ||
|
||
import ( | ||
configv1 "github.com/openshift/api/config/v1" | ||
openshiftcontrolplanev1 "github.com/openshift/api/openshiftcontrolplane/v1" | ||
"github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/configobservation" | ||
) | ||
|
||
func disabledBuildControllers(listers configobservation.Listers) ([]openshiftcontrolplanev1.OpenShiftControllerName, error) { | ||
cv, err := listers.ClusterVersionLister.Get("version") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var capabilityEnabled bool | ||
for _, capability := range cv.Status.Capabilities.EnabledCapabilities { | ||
if capability == configv1.ClusterVersionCapabilityBuild { | ||
capabilityEnabled = true | ||
break | ||
} | ||
} | ||
if capabilityEnabled { | ||
return nil, nil | ||
} | ||
return []openshiftcontrolplanev1.OpenShiftControllerName{ | ||
openshiftcontrolplanev1.OpenShiftBuildController, | ||
openshiftcontrolplanev1.OpenShiftBuildConfigChangeController, | ||
openshiftcontrolplanev1.OpenShiftBuilderServiceAccountController, | ||
}, nil | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
pkg/operator/configobservation/controllers/capability_deploymentconfigs.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package controllers | ||
|
||
import ( | ||
configv1 "github.com/openshift/api/config/v1" | ||
openshiftcontrolplanev1 "github.com/openshift/api/openshiftcontrolplane/v1" | ||
"github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/configobservation" | ||
) | ||
|
||
func disabledDeploymentConfigControllers(listers configobservation.Listers) ([]openshiftcontrolplanev1.OpenShiftControllerName, error) { | ||
cv, err := listers.ClusterVersionLister.Get("version") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var capabilityEnabled bool | ||
for _, capability := range cv.Status.Capabilities.EnabledCapabilities { | ||
if capability == configv1.ClusterVersionCapabilityDeploymentConfig { | ||
capabilityEnabled = true | ||
break | ||
} | ||
} | ||
if capabilityEnabled { | ||
return nil, nil | ||
} | ||
return []openshiftcontrolplanev1.OpenShiftControllerName{ | ||
openshiftcontrolplanev1.OpenShiftDeploymentConfigController, | ||
openshiftcontrolplanev1.OpenShiftDeployerServiceAccountController, | ||
}, nil | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
pkg/operator/configobservation/controllers/capability_imageregistry.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
openshiftcontrolplanev1 "github.com/openshift/api/openshiftcontrolplane/v1" | ||
"github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/configobservation" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func disabledImageRegistryControllers(listers configobservation.Listers) ([]openshiftcontrolplanev1.OpenShiftControllerName, error) { | ||
cv, err := listers.ClusterVersionLister.Get("version") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var imageRegistryCapabilityEnabled bool | ||
for _, capability := range cv.Status.Capabilities.EnabledCapabilities { | ||
if capability == configv1.ClusterVersionCapabilityImageRegistry { | ||
imageRegistryCapabilityEnabled = true | ||
break | ||
} | ||
} | ||
controllers := []openshiftcontrolplanev1.OpenShiftControllerName{ | ||
openshiftcontrolplanev1.OpenShiftServiceAccountPullSecretsController, | ||
} | ||
if !imageRegistryCapabilityEnabled { | ||
return controllers, nil | ||
} | ||
|
||
co, err := listers.ClusterOperatorLister.Get("image-registry") | ||
if err != nil && !errors.IsNotFound(err) { | ||
return nil, fmt.Errorf("unable to retrieve clusteroperators.config.openshift.io/image-registry: %w", err) | ||
} | ||
if errors.IsNotFound(err) { | ||
klog.V(4).Infof("clusteroperators.config.openshift.io/image-registry does not exist yet.") | ||
return controllers, nil | ||
} | ||
|
||
// Check if internal image registry is "Removed". Any condition should do. | ||
if len(co.Status.Conditions) == 0 { | ||
return nil, fmt.Errorf("clusteroperators.config.openshift.io/image-registry conditions do not yet exist") | ||
} | ||
if co.Status.Conditions[0].Reason == "Removed" { | ||
return controllers, nil | ||
} | ||
// ImageRegistry capability is enabled, and internal image registry is enabled, nothing to disable. | ||
return nil, nil | ||
} |
95 changes: 95 additions & 0 deletions
95
pkg/operator/configobservation/controllers/observe_controllers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
|
||
openshiftcontrolplanev1 "github.com/openshift/api/openshiftcontrolplane/v1" | ||
"github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/configobservation" | ||
"github.com/openshift/library-go/pkg/operator/configobserver" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
var allControllers = []string{ | ||
string(openshiftcontrolplanev1.OpenShiftServiceAccountController), | ||
string(openshiftcontrolplanev1.OpenShiftDefaultRoleBindingsController), | ||
string(openshiftcontrolplanev1.OpenShiftServiceAccountPullSecretsController), | ||
string(openshiftcontrolplanev1.OpenShiftOriginNamespaceController), | ||
string(openshiftcontrolplanev1.OpenShiftBuildController), | ||
string(openshiftcontrolplanev1.OpenShiftBuildConfigChangeController), | ||
string(openshiftcontrolplanev1.OpenShiftBuilderServiceAccountController), | ||
string(openshiftcontrolplanev1.OpenShiftDeployerController), | ||
string(openshiftcontrolplanev1.OpenShiftDeployerServiceAccountController), | ||
string(openshiftcontrolplanev1.OpenShiftDeploymentConfigController), | ||
string(openshiftcontrolplanev1.OpenShiftImageTriggerController), | ||
string(openshiftcontrolplanev1.OpenShiftImageImportController), | ||
string(openshiftcontrolplanev1.OpenShiftImageSignatureImportController), | ||
string(openshiftcontrolplanev1.OpenShiftTemplateInstanceController), | ||
string(openshiftcontrolplanev1.OpenShiftTemplateInstanceFinalizerController), | ||
string(openshiftcontrolplanev1.OpenShiftUnidlingController), | ||
// the following two controllers are now part of route-controller-manager, which split | ||
// some crontollers off from openshift-controller-manager, but still uses the same config. | ||
string(openshiftcontrolplanev1.OpenShiftIngressIPController), | ||
string(openshiftcontrolplanev1.OpenShiftIngressToRouteController), | ||
} | ||
|
||
type disabledControllersFunc func(listers configobservation.Listers) ([]openshiftcontrolplanev1.OpenShiftControllerName, error) | ||
|
||
var disabledControllerFuncs = []disabledControllersFunc{ | ||
disabledImageRegistryControllers, | ||
disabledBuildControllers, | ||
disabledDeploymentConfigControllers, | ||
} | ||
|
||
func ObserveControllers(genericListers configobserver.Listers, recorder events.Recorder, existingConfig map[string]interface{}) (map[string]interface{}, []error) { | ||
listers := genericListers.(configobservation.Listers) | ||
observedConfig := map[string]interface{}{} | ||
var errs []error | ||
|
||
previousValue, _, err := unstructured.NestedStringSlice(existingConfig, "controllers") | ||
if err != nil { | ||
return observedConfig, append(errs, fmt.Errorf("unable to parse existing controllers value: %w", err)) | ||
} | ||
previousConfig := map[string]interface{}{} | ||
unstructured.SetNestedStringSlice(previousConfig, previousValue, "controllers") | ||
|
||
controllers := append([]string{}, allControllers...) | ||
unstructured.SetNestedStringSlice(observedConfig, controllers, "controllers") | ||
|
||
// compile list of controllers to disable | ||
var disabledControllers []openshiftcontrolplanev1.OpenShiftControllerName | ||
for _, getDisabledControllers := range disabledControllerFuncs { | ||
disabled, err := getDisabledControllers(listers) | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
disabledControllers = append(disabledControllers, disabled...) | ||
} | ||
if len(errs) > 0 { | ||
return previousConfig, errs | ||
} | ||
// mark controllers as disabled | ||
for _, name := range disabledControllers { | ||
controllers = disableController(controllers, string(name)) | ||
} | ||
controllersSort(controllers).Sort() | ||
err = unstructured.SetNestedStringSlice(observedConfig, controllers, "controllers") | ||
if err != nil { | ||
return previousConfig, append(errs, fmt.Errorf("error setting controllers value: %w", err)) | ||
} | ||
return observedConfig, nil | ||
} | ||
|
||
func disableController(controllers []string, controller string) []string { | ||
for i, c := range controllers { | ||
switch c { | ||
case controller: | ||
controllers[i] = "-" + controller | ||
return controllers | ||
case "-" + controller: | ||
return controllers | ||
} | ||
} | ||
return append(controllers, "-"+controller) | ||
} |
Oops, something went wrong.