-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Openshift] Admin user can disable auto creation of RBAC resources
- Loading branch information
1 parent
4162dd5
commit 221391d
Showing
8 changed files
with
294 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ spec: | |
value: "true" | ||
- name: pipelineTemplates | ||
value: "true" | ||
params: | ||
- name: createRbacResource | ||
value: "true" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,119 @@ | ||
package tektonconfig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tektoncd/operator/pkg/apis/operator/v1alpha1" | ||
"github.com/tektoncd/operator/pkg/client/clientset/versioned" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func createInstallerSet(ctx context.Context, oc versioned.Interface, tc *v1alpha1.TektonConfig, labels map[string]string, | ||
releaseVersion, component, installerSetName string) error { | ||
|
||
is := makeInstallerSet(tc, installerSetName, releaseVersion, labels) | ||
|
||
createdIs, err := oc.OperatorV1alpha1().TektonInstallerSets(). | ||
Create(ctx, is, metav1.CreateOptions{}) | ||
if err != nil && !errors.IsAlreadyExists(err) { | ||
return err | ||
} | ||
|
||
if len(tc.Status.TektonInstallerSet) == 0 { | ||
tc.Status.TektonInstallerSet = map[string]string{} | ||
} | ||
|
||
// Update the status of tektonConfig with created installerSet name | ||
tc.Status.TektonInstallerSet[component] = createdIs.Name | ||
tc.Status.SetVersion(releaseVersion) | ||
|
||
_, err = oc.OperatorV1alpha1().TektonConfigs(). | ||
UpdateStatus(ctx, tc, metav1.UpdateOptions{}) | ||
|
||
return err | ||
} | ||
|
||
func makeInstallerSet(tc *v1alpha1.TektonConfig, name, releaseVersion string, labels map[string]string) *v1alpha1.TektonInstallerSet { | ||
ownerRef := *metav1.NewControllerRef(tc, tc.GetGroupVersionKind()) | ||
return &v1alpha1.TektonInstallerSet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Labels: labels, | ||
Annotations: map[string]string{ | ||
releaseVersionKey: releaseVersion, | ||
targetNamespaceKey: tc.Spec.TargetNamespace, | ||
}, | ||
OwnerReferences: []metav1.OwnerReference{ownerRef}, | ||
}, | ||
} | ||
} | ||
|
||
func deleteInstallerSet(ctx context.Context, oc versioned.Interface, tc *v1alpha1.TektonConfig, component string) error { | ||
|
||
compInstallerSet, ok := tc.Status.TektonInstallerSet[component] | ||
if !ok { | ||
return nil | ||
} | ||
|
||
if compInstallerSet != "" { | ||
// delete the installer set | ||
err := oc.OperatorV1alpha1().TektonInstallerSets(). | ||
Delete(ctx, tc.Status.TektonInstallerSet[component], metav1.DeleteOptions{}) | ||
if err != nil && !errors.IsNotFound(err) { | ||
return err | ||
} | ||
|
||
// clear the name of installer set from TektonAddon status | ||
delete(tc.Status.TektonInstallerSet, component) | ||
_, err = oc.OperatorV1alpha1().TektonConfigs(). | ||
UpdateStatus(ctx, tc, metav1.UpdateOptions{}) | ||
if err != nil && !errors.IsNotFound(err) { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// checkIfInstallerSetExist checks if installer set exists for a component and return true/false based on it | ||
// and if installer set which already exist is of older version then it deletes and return false to create a new | ||
// installer set | ||
func checkIfInstallerSetExist(ctx context.Context, oc versioned.Interface, relVersion string, | ||
tc *v1alpha1.TektonConfig, component string) (bool, error) { | ||
|
||
// Check if installer set is already created | ||
compInstallerSet, ok := tc.Status.TektonInstallerSet[component] | ||
if !ok { | ||
return false, nil | ||
} | ||
|
||
if compInstallerSet != "" { | ||
// if already created then check which version it is | ||
ctIs, err := oc.OperatorV1alpha1().TektonInstallerSets(). | ||
Get(ctx, compInstallerSet, metav1.GetOptions{}) | ||
if err != nil { | ||
if errors.IsNotFound(err) { | ||
return false, nil | ||
} | ||
return false, err | ||
} | ||
|
||
if version, ok := ctIs.Annotations[releaseVersionKey]; ok && version == relVersion { | ||
// if installer set already exist and release version is same | ||
// then ignore and move on | ||
return true, nil | ||
} | ||
|
||
// release version doesn't exist or is different from expected | ||
// deleted existing InstallerSet and create a new one | ||
|
||
err = oc.OperatorV1alpha1().TektonInstallerSets(). | ||
Delete(ctx, compInstallerSet, metav1.DeleteOptions{}) | ||
if err != nil { | ||
return false, err | ||
} | ||
} | ||
|
||
return false, nil | ||
} |
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
Oops, something went wrong.