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

OCPBUGS-17157: label non-OLM resources #3017

Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

configclientset "github.com/openshift/client-go/config/clientset/versioned"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/validatingroundtripper"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -139,6 +140,9 @@ func main() {
}
config := mgr.GetConfig()

// create a config that validates we're creating objects with labels
validatingConfig := validatingroundtripper.Wrap(config)

versionedConfigClient, err := configclientset.NewForConfig(config)
if err != nil {
logger.WithError(err).Fatal("error configuring openshift proxy client")
Expand All @@ -147,7 +151,7 @@ func main() {
if err != nil {
logger.WithError(err).Fatal("error configuring config client")
}
opClient, err := operatorclient.NewClientFromRestConfig(config)
opClient, err := operatorclient.NewClientFromRestConfig(validatingConfig)
if err != nil {
logger.WithError(err).Fatal("error configuring operator client")
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/bundle/bundle_unpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,19 @@ func newBundleUnpackResult(lookup *operatorsv1alpha1.BundleLookup) *BundleUnpack

func (c *ConfigMapUnpacker) job(cmRef *corev1.ObjectReference, bundlePath string, secrets []corev1.LocalObjectReference, annotationUnpackTimeout time.Duration) *batchv1.Job {
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
install.OLMManagedLabelKey: install.OLMManagedLabelValue,
},
},
Spec: batchv1.JobSpec{
//ttlSecondsAfterFinished: 0 // can use in the future to not have to clean up job
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: cmRef.Name,
Labels: map[string]string{
stevekuznetsov marked this conversation as resolved.
Show resolved Hide resolved
install.OLMManagedLabelKey: install.OLMManagedLabelValue,
},
},
Spec: corev1.PodSpec{
// With restartPolicy = "OnFailure" when the spec.backoffLimit is reached, the job controller will delete all
Expand Down Expand Up @@ -687,6 +695,7 @@ func (c *ConfigMapUnpacker) ensureRole(cmRef *corev1.ObjectReference) (role *rba
fresh.SetNamespace(cmRef.Namespace)
fresh.SetName(cmRef.Name)
fresh.SetOwnerReferences([]metav1.OwnerReference{ownerRef(cmRef)})
fresh.SetLabels(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue})

role, err = c.roleLister.Roles(fresh.GetNamespace()).Get(fresh.GetName())
if err != nil {
Expand Down Expand Up @@ -730,6 +739,7 @@ func (c *ConfigMapUnpacker) ensureRoleBinding(cmRef *corev1.ObjectReference) (ro
fresh.SetNamespace(cmRef.Namespace)
fresh.SetName(cmRef.Name)
fresh.SetOwnerReferences([]metav1.OwnerReference{ownerRef(cmRef)})
fresh.SetLabels(map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue})

roleBinding, err = c.rbLister.RoleBindings(fresh.GetNamespace()).Get(fresh.GetName())
if err != nil {
Expand Down
31 changes: 25 additions & 6 deletions pkg/controller/bundle/bundle_unpacker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand All @@ -224,7 +225,8 @@ func TestConfigMapUnpacker(t *testing.T) {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Name: pathHash,
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
Expand Down Expand Up @@ -369,6 +371,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand Down Expand Up @@ -402,6 +405,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand Down Expand Up @@ -437,6 +441,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand All @@ -452,7 +457,8 @@ func TestConfigMapUnpacker(t *testing.T) {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Name: digestHash,
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
Expand Down Expand Up @@ -607,6 +613,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "operators.coreos.com/v1alpha1",
Expand Down Expand Up @@ -705,6 +712,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand All @@ -720,7 +728,8 @@ func TestConfigMapUnpacker(t *testing.T) {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Name: digestHash,
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
Expand Down Expand Up @@ -877,6 +886,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand Down Expand Up @@ -910,6 +920,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: digestHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand Down Expand Up @@ -967,6 +978,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand All @@ -982,7 +994,8 @@ func TestConfigMapUnpacker(t *testing.T) {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Name: pathHash,
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
Expand Down Expand Up @@ -1124,6 +1137,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "operators.coreos.com/v1alpha1",
Expand Down Expand Up @@ -1199,6 +1213,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand All @@ -1214,7 +1229,8 @@ func TestConfigMapUnpacker(t *testing.T) {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Name: pathHash,
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
Expand Down Expand Up @@ -1368,6 +1384,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "operators.coreos.com/v1alpha1",
Expand Down Expand Up @@ -1442,6 +1459,7 @@ func TestConfigMapUnpacker(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Namespace: "ns-a",
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "v1",
Expand All @@ -1457,7 +1475,8 @@ func TestConfigMapUnpacker(t *testing.T) {
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: pathHash,
Name: pathHash,
Labels: map[string]string{install.OLMManagedLabelKey: install.OLMManagedLabelValue},
},
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/install/certresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
service.SetName(ServiceName(deploymentName))
service.SetNamespace(i.owner.GetNamespace())
ownerutil.AddNonBlockingOwner(service, i.owner)
service.SetLabels(map[string]string{OLMManagedLabelKey: OLMManagedLabelValue})

existingService, err := i.strategyClient.GetOpLister().CoreV1().ServiceLister().Services(i.owner.GetNamespace()).Get(service.GetName())
if err == nil {
Expand Down Expand Up @@ -366,6 +367,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
}
secretRole.SetName(secret.GetName())
secretRole.SetNamespace(i.owner.GetNamespace())
secretRole.SetLabels(map[string]string{OLMManagedLabelKey: OLMManagedLabelValue})

existingSecretRole, err := i.strategyClient.GetOpLister().RbacV1().RoleLister().Roles(i.owner.GetNamespace()).Get(secretRole.GetName())
if err == nil {
Expand Down Expand Up @@ -412,6 +414,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
}
secretRoleBinding.SetName(secret.GetName())
secretRoleBinding.SetNamespace(i.owner.GetNamespace())
secretRoleBinding.SetLabels(map[string]string{OLMManagedLabelKey: OLMManagedLabelValue})

existingSecretRoleBinding, err := i.strategyClient.GetOpLister().RbacV1().RoleBindingLister().RoleBindings(i.owner.GetNamespace()).Get(secretRoleBinding.GetName())
if err == nil {
Expand Down Expand Up @@ -454,6 +457,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
},
}
authDelegatorClusterRoleBinding.SetName(service.GetName() + "-system:auth-delegator")
authDelegatorClusterRoleBinding.SetLabels(map[string]string{OLMManagedLabelKey: OLMManagedLabelValue})

existingAuthDelegatorClusterRoleBinding, err := i.strategyClient.GetOpLister().RbacV1().ClusterRoleBindingLister().Get(authDelegatorClusterRoleBinding.GetName())
if err == nil {
Expand Down Expand Up @@ -502,6 +506,7 @@ func (i *StrategyDeploymentInstaller) installCertRequirementsForDeployment(deplo
}
authReaderRoleBinding.SetName(service.GetName() + "-auth-reader")
authReaderRoleBinding.SetNamespace(KubeSystem)
authReaderRoleBinding.SetLabels(map[string]string{OLMManagedLabelKey: OLMManagedLabelValue})

existingAuthReaderRoleBinding, err := i.strategyClient.GetOpLister().RbacV1().RoleBindingLister().RoleBindings(KubeSystem).Get(authReaderRoleBinding.GetName())
if err == nil {
Expand Down
Loading