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

Add manual approval component in Operator #2138

Merged
merged 3 commits into from
May 13, 2024
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
3 changes: 3 additions & 0 deletions components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ results:
triggers:
github: tektoncd/triggers
version: v0.27.0
manual-approval-gate:
github: openshift-pipelines/manual-approval-gate
version: v0.1.0
53 changes: 53 additions & 0 deletions config/base/300-operator_v1alpha1_manualapprovalgate_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024 The Tekton 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.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: manualapprovalgates.operator.tekton.dev
labels:
version: "devel"
operator.tekton.dev/release: "devel"
spec:
group: operator.tekton.dev
names:
kind: ManualApprovalGate
listKind: ManualApprovalGateList
plural: manualapprovalgates
singular: manualapprovalgate
shortNames:
- mag
preserveUnknownFields: false
scope: Cluster
versions:
- name: v1alpha1
served: true
storage: true
subresources:
status: {}
additionalPrinterColumns:
- jsonPath: .status.version
name: Version
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- jsonPath: ".status.conditions[?(@.type==\"Ready\")].message"
name: Reason
type: string
schema:
openAPIV3Schema:
type: object
description: Schema for the ManualApprovalGate API
x-kubernetes-preserve-unknown-fields: true
1 change: 1 addition & 0 deletions config/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resources:
- 300-operator_v1alpha1_result_crd.yaml
- 300-operator_v1alpha1_installer_set_crd.yaml
- 300-operator_v1alpha1_hub_crd.yaml
- 300-operator_v1alpha1_manualapprovalgate_crd.yaml
- config-logging.yaml
- config-observability.yaml
- tekton-config-defaults.yaml
Expand Down
15 changes: 15 additions & 0 deletions config/base/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,18 @@ rules:
- delete
- update
- patch
- apiGroups:
- openshift-pipelines.org
resources:
- approvaltasks
- approvaltasks/status
verbs:
- add
- get
- list
- create
- update
- delete
- deletecollection
- patch
- watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 The Tekton 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.

apiVersion: operator.tekton.dev/v1alpha1
kind: ManualApprovalGate
metadata:
name: manual-approval-gate
spec:
targetNamespace: tekton-pipelines
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 The Tekton 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.

apiVersion: operator.tekton.dev/v1alpha1
kind: ManualApprovalGate
metadata:
name: manual-approval-gate
spec:
targetNamespace: openshift-pipelines
2 changes: 1 addition & 1 deletion config/kubernetes/base/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
image: ko://github.com/tektoncd/operator/cmd/kubernetes/operator
args:
- "-controllers"
- "tektonconfig,tektonpipeline,tektontrigger,tektonhub,tektonchain,tektonresult,tektondashboard"
- "tektonconfig,tektonpipeline,tektontrigger,tektonhub,tektonchain,tektonresult,tektondashboard,manualapprovalgate"
- "-unique-process-name"
- "tekton-operator-lifecycle"
imagePullPolicy: Always
Expand Down
2 changes: 1 addition & 1 deletion config/openshift/base/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
image: ko://github.com/tektoncd/operator/cmd/openshift/operator
args:
- "-controllers"
- "tektonconfig,tektonpipeline,tektontrigger,tektonhub,tektonchain,tektonaddon,tektonresult,openshiftpipelinesascode"
- "tektonconfig,tektonpipeline,tektontrigger,tektonhub,tektonchain,tektonaddon,tektonresult,openshiftpipelinesascode,manualapprovalgate"
- "-unique-process-name"
- "tekton-operator-lifecycle"
imagePullPolicy: Always
Expand Down
43 changes: 43 additions & 0 deletions hack/fetch-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,46 @@ release_yaml_pac() {
echo ""
}

release_yaml_manualapprovalgate() {
echo fetching '|' version: ${1}
local version=$1

ko_data=${SCRIPT_DIR}/cmd/${TARGET}/operator/kodata
if [ ${version} == "latest" ]
then
version=$(curl -sL https://api.github.com/repos/openshift-pipelines/manual-approval-gate/releases | jq -r ".[].tag_name" | sort -Vr | head -n1)
dirPath=${ko_data}/manual-approval-gate/0.0.0-latest
else
dirVersion=${version//v}
dirPath=${ko_data}/manual-approval-gate/${dirVersion}
fi
mkdir -p ${dirPath} || true

dest=${dirPath}
fileName=release-${TARGET}.yaml
destinationFile=${dest}/${fileName}

if [ -f "$destinationFile" ] && [ $FORCE_FETCH_RELEASE = "false" ]; then
if grep -Eq "$version" $destinationFile;
then
echo "release file already exist with required version, skipping!"
echo ""
fi
fi

url="https://github.com/openshift-pipelines/manual-approval-gate/releases/download/${version}/${fileName}"
echo ${url}
http_response=$(curl -s -L -o ${destinationFile} -w "%{http_code}" ${url})
echo url: ${url}
if [[ $http_response != "200" ]]; then
echo "Error: failed to get manual-approval-gate yaml, status code: $http_response"
exit 1
fi
echo "Info: Added Manual-Approval-Gate/$fileName:$version release yaml !!"
echo ""

}


release_yaml_hub() {
echo fetching '|' component: ${1} '|' version: ${2}
Expand Down Expand Up @@ -278,6 +318,9 @@ main() {
hub_version=$(go run ./cmd/tool component-version ${CONFIG} hub)
release_yaml_hub hub ${hub_version}

mag_version=$(go run ./cmd/tool component-version ${CONFIG} manual-approval-gate)
release_yaml_manualapprovalgate ${mag_version}

# copy pruner rbac/sa yaml
copy_pruner_yaml

Expand Down
1 change: 1 addition & 0 deletions pkg/apis/operator/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,6 @@ var (
ChainResourceName = "chain"
OperandTektoncdChains = "tektoncd-chains"
OpenShiftPipelinesAsCodeName = "pipelines-as-code"
ManualApprovalGates = "manual-approval-gate"
PrunerResourceName = "tektoncd-pruner"
)
156 changes: 156 additions & 0 deletions pkg/apis/operator/v1alpha1/manualapprovalgate_lifecycle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
Copyright 2024 The Tekton 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.
*/

package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
)

var (
_ TektonComponentStatus = (*ManualApprovalGateStatus)(nil)

magCondSet = apis.NewLivingConditionSet(
DependenciesInstalled,
PreReconciler,
InstallerSetAvailable,
InstallerSetReady,
PostReconciler,
)
)

// GroupVersionKind returns SchemeGroupVersion of a ManualApprovalGate
func (mag *ManualApprovalGate) GroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind(KindManualApprovalGate)
}

func (mag *ManualApprovalGate) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind(KindManualApprovalGate)
}
PuneetPunamiya marked this conversation as resolved.
Show resolved Hide resolved

// GetCondition returns the current condition of a given condition type
func (mag *ManualApprovalGateStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return magCondSet.Manage(mag).GetCondition(t)
}

// InitializeConditions initializes conditions of an ManualApprovalGateStatus
func (mag *ManualApprovalGateStatus) InitializeConditions() {
magCondSet.Manage(mag).InitializeConditions()
}

// IsReady looks at the conditions returns true if they are all true.
func (mag *ManualApprovalGateStatus) IsReady() bool {
return magCondSet.Manage(mag).IsHappy()
}

func (mag *ManualApprovalGateStatus) MarkPreReconcilerComplete() {
magCondSet.Manage(mag).MarkTrue(PreReconciler)
}

func (mag *ManualApprovalGateStatus) MarkInstallerSetAvailable() {
magCondSet.Manage(mag).MarkTrue(InstallerSetAvailable)
}

func (mag *ManualApprovalGateStatus) MarkInstallerSetReady() {
magCondSet.Manage(mag).MarkTrue(InstallerSetReady)
}

func (mag *ManualApprovalGateStatus) MarkPostReconcilerComplete() {
magCondSet.Manage(mag).MarkTrue(PostReconciler)
}

// MarkDependenciesInstalled marks the DependenciesInstalled status as true.
func (mag *ManualApprovalGateStatus) MarkDependenciesInstalled() {
magCondSet.Manage(mag).MarkTrue(DependenciesInstalled)
}

func (mag *ManualApprovalGateStatus) MarkNotReady(msg string) {
magCondSet.Manage(mag).MarkFalse(
apis.ConditionReady,
"Error",
"Ready: %s", msg)
PuneetPunamiya marked this conversation as resolved.
Show resolved Hide resolved
}

func (mag *ManualApprovalGateStatus) MarkPreReconcilerFailed(msg string) {
mag.MarkNotReady("PreReconciliation failed")
magCondSet.Manage(mag).MarkFalse(
PreReconciler,
"Error",
"PreReconciliation failed with message: %s", msg)
}

func (mag *ManualApprovalGateStatus) MarkInstallerSetNotAvailable(msg string) {
mag.MarkNotReady("TektonInstallerSet not ready")
magCondSet.Manage(mag).MarkFalse(
InstallerSetAvailable,
"Error",
"Installer set not ready: %s", msg)
}

func (mag *ManualApprovalGateStatus) MarkInstallerSetNotReady(msg string) {
mag.MarkNotReady("TektonInstallerSet not ready")
magCondSet.Manage(mag).MarkFalse(
InstallerSetReady,
"Error",
"Installer set not ready: %s", msg)
}

func (mag *ManualApprovalGateStatus) MarkPostReconcilerFailed(msg string) {
mag.MarkNotReady("PostReconciliation failed")
magCondSet.Manage(mag).MarkFalse(
PostReconciler,
"Error",
"PostReconciliation failed with message: %s", msg)
}

// MarkDependencyInstalling marks the DependenciesInstalled status as false with the
// given message.
func (mag *ManualApprovalGateStatus) MarkDependencyInstalling(msg string) {
mag.MarkNotReady("Dependencies installing")
magCondSet.Manage(mag).MarkFalse(
DependenciesInstalled,
"Error",
"Dependency installing: %s", msg)
}

// MarkDependencyMissing marks the DependenciesInstalled status as false with the
// given message.
func (mag *ManualApprovalGateStatus) MarkDependencyMissing(msg string) {
mag.MarkNotReady("Missing Dependencies for ManualApprovalGate")
magCondSet.Manage(mag).MarkFalse(
DependenciesInstalled,
"Error",
"Dependency missing: %s", msg)
}

func (mag *ManualApprovalGateStatus) GetTektonInstallerSet() string {
return mag.TektonInstallerSet
}

func (mag *ManualApprovalGateStatus) SetTektonInstallerSet(installerSet string) {
mag.TektonInstallerSet = installerSet
}

// GetVersion gets the currently installed version of the component.
func (mag *ManualApprovalGateStatus) GetVersion() string {
return mag.Version
}

// SetVersion sets the currently installed version of the component.
func (mag *ManualApprovalGateStatus) SetVersion(version string) {
mag.Version = version
}
Loading