-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 support for conversion webhook 🍸 #2413
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"os" | ||
|
||
defaultconfig "github.com/tektoncd/pipeline/pkg/apis/config" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
"github.com/tektoncd/pipeline/pkg/contexts" | ||
|
@@ -37,6 +38,7 @@ import ( | |
"knative.dev/pkg/webhook/certificates" | ||
"knative.dev/pkg/webhook/configmaps" | ||
"knative.dev/pkg/webhook/resourcesemantics" | ||
"knative.dev/pkg/webhook/resourcesemantics/conversion" | ||
"knative.dev/pkg/webhook/resourcesemantics/defaulting" | ||
"knative.dev/pkg/webhook/resourcesemantics/validation" | ||
) | ||
|
@@ -85,6 +87,9 @@ func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher | |
} | ||
|
||
func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { | ||
// Decorate contexts with the current state of the config. | ||
store := defaultconfig.NewStore(logging.FromContext(ctx).Named("config-store")) | ||
store.WatchConfigs(cmw) | ||
return validation.NewAdmissionController(ctx, | ||
|
||
// Name of the resource webhook. | ||
|
@@ -98,7 +103,7 @@ func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher | |
|
||
// A function that infuses the context passed to Validate/SetDefaults with custom metadata. | ||
func(ctx context.Context) context.Context { | ||
return ctx | ||
return contexts.WithUpgradeViaDefaulting(store.ToContext(ctx)) | ||
}, | ||
|
||
// Whether to disallow unknown fields. | ||
|
@@ -124,6 +129,68 @@ func NewConfigValidationController(ctx context.Context, cmw configmap.Watcher) * | |
) | ||
} | ||
|
||
func NewConversionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl { | ||
// nolint: golint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we not want to lint this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😅 well, I need to find a better name than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what variable name to use to be honest 🙃 |
||
var ( | ||
v1alpha1_ = v1alpha1.SchemeGroupVersion.Version | ||
v1beta1_ = v1beta1.SchemeGroupVersion.Version | ||
) | ||
|
||
return conversion.NewConversionController(ctx, | ||
// The path on which to serve the webhook | ||
"/resource-conversion", | ||
|
||
// Specify the types of custom resource definitions that should be converted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the keys are the types to convert TO and the zygotes are the version to convert FROM is that right? im not 100% clear either way tho so maybe some more detail in the comment might help? |
||
map[schema.GroupKind]conversion.GroupKindConversion{ | ||
v1beta1.Kind("Task"): { | ||
DefinitionName: pipeline.TaskResource.String(), | ||
HubVersion: v1alpha1_, | ||
Zygotes: map[string]conversion.ConvertibleObject{ | ||
v1alpha1_: &v1alpha1.Task{}, | ||
v1beta1_: &v1beta1.Task{}, | ||
}, | ||
}, | ||
v1beta1.Kind("ClusterTask"): { | ||
DefinitionName: pipeline.ClusterTaskResource.String(), | ||
HubVersion: v1alpha1_, | ||
Zygotes: map[string]conversion.ConvertibleObject{ | ||
v1alpha1_: &v1alpha1.ClusterTask{}, | ||
v1beta1_: &v1beta1.ClusterTask{}, | ||
}, | ||
}, | ||
v1beta1.Kind("TaskRun"): { | ||
DefinitionName: pipeline.TaskRunResource.String(), | ||
HubVersion: v1alpha1_, | ||
Zygotes: map[string]conversion.ConvertibleObject{ | ||
v1alpha1_: &v1alpha1.TaskRun{}, | ||
v1beta1_: &v1beta1.TaskRun{}, | ||
}, | ||
}, | ||
v1beta1.Kind("Pipeline"): { | ||
DefinitionName: pipeline.PipelineResource.String(), | ||
HubVersion: v1alpha1_, | ||
Zygotes: map[string]conversion.ConvertibleObject{ | ||
v1alpha1_: &v1alpha1.Pipeline{}, | ||
v1beta1_: &v1beta1.Pipeline{}, | ||
}, | ||
}, | ||
v1beta1.Kind("PipelineRun"): { | ||
DefinitionName: pipeline.PipelineRunResource.String(), | ||
HubVersion: v1alpha1_, | ||
Zygotes: map[string]conversion.ConvertibleObject{ | ||
v1alpha1_: &v1alpha1.PipelineRun{}, | ||
v1beta1_: &v1beta1.PipelineRun{}, | ||
}, | ||
}, | ||
}, | ||
|
||
// A function that infuses the context passed to ConvertTo/ConvertFrom/SetDefaults with custom metadata | ||
func(ctx context.Context) context.Context { | ||
return ctx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you want the ctx stuff here too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed what was in |
||
}, | ||
) | ||
} | ||
|
||
func main() { | ||
serviceName := os.Getenv("WEBHOOK_SERVICE_NAME") | ||
if serviceName == "" { | ||
|
@@ -146,5 +213,6 @@ func main() { | |
NewDefaultingAdmissionController, | ||
NewValidationAdmissionController, | ||
NewConfigValidationController, | ||
NewConversionController, | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ limitations under the License. | |
|
||
package pipeline | ||
|
||
import "k8s.io/apimachinery/pkg/runtime/schema" | ||
|
||
const ( | ||
// GroupName is the Kubernetes resource group name for Pipeline types. | ||
GroupName = "tekton.dev" | ||
|
@@ -41,3 +43,42 @@ const ( | |
// ConditionCheckKey is used as the label identifier for a ConditionCheck | ||
ConditionCheckKey = "/conditionCheck" | ||
) | ||
|
||
var ( | ||
// TaskResource represents a Tekton Task | ||
TaskResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "tasks", | ||
} | ||
// ClusterTaskResource represents a Tekton ClusterTask | ||
ClusterTaskResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "clustertasks", | ||
} | ||
// TaskRunResource represents a Tekton TaskRun | ||
TaskRunResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "taskruns", | ||
} | ||
// PipelineResource represents a Tekton Pipeline | ||
PipelineResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "pipelines", | ||
} | ||
// PipelineRunResource represents a Tekton PipelineRun | ||
PipelineRunResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "pipelineruns", | ||
} | ||
|
||
// PipelineResourceResource represents a Tekton PipelineResource | ||
PipelineResourceResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "pipelineresources", | ||
} | ||
// ConditionResource represents a Tekton Condition | ||
ConditionResource = schema.GroupResource{ | ||
Group: GroupName, | ||
Resource: "conditions", | ||
} | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im not 100% clear on why these are required now or where they are used? does the conversion webhook automatically detect these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do here : https://github.com/tektoncd/pipeline/pull/2413/files#diff-58de452513b7e8d8d3cfea23eb4ae6a8R170 (and we might do at other parts of the code). It makes it a bit easier to get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contexts.WithUpgradeViaDefaulting
Are you using this upgrade marker for anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we do