Skip to content

Commit

Permalink
Merge pull request #7 from ifireball/pds-reconcile
Browse files Browse the repository at this point in the history
feat(RHTAPWATCH-817): Implement template application logic
  • Loading branch information
ifireball authored Mar 19, 2024
2 parents ba51d9b + 346426a commit 6cf5993
Show file tree
Hide file tree
Showing 16 changed files with 726 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'

- name: Test
run: make test
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
"cSpell.words": [
"apierrors",
"apimachinery",
"apischema",
"clientgoscheme",
"controllerutil",
"finalizers",
"healthz",
"hyphenize",
"konflux",
"kubebuilder",
"logr",
"metav",
"metricsserver",
"OIDC",
"pdst",
"projctl",
"projctlv",
"projectdevelopmentstream",
"projectdevelopmentstreams",
"projectdevelopmentstreamtemplate",
"projectdevelopmentstreamtemplates",
"subresource",
"utilruntime"
"upsert",
"utilruntime",
"vals"
]
}
38 changes: 27 additions & 11 deletions api/v1beta1/projectdevelopmentstream_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,47 @@ package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// +kubebuilder:pruning:PreserveUnknownFields
type UnstructuredObj struct {
unstructured.Unstructured `json:",inline"`
// Provide a value for a variable specified in an associated
// ProjectDevelopmentStreamTemplate
type ProjectDevelopmentStreamSpecTemplateValue struct {
// The name of the template variable to provide a value for
Name string `json:"name"`
// The value to be placed in the template variable
Value string `json:"value"`
}

// ProjectDevelopmentStreamSpecTemplateRef defines which optional template is
// associated with this ProjectDevelopmentStream and how to apply it
type ProjectDevelopmentStreamSpecTemplateRef struct {
// The name of the ProjectDevelopmentStreamTemplate to use
Name string `json:"name"`
// Values for template variables
Values []ProjectDevelopmentStreamSpecTemplateValue `json:"values,omitempty"`
}

// ProjectDevelopmentStreamSpec defines the desired state of ProjectDevelopmentStream
type ProjectDevelopmentStreamSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// The name of the project this stream belongs to
Project string `json:"project,omitempty"`
Resources []UnstructuredObj `json:"resources,omitempty"`
Project string `json:"project,omitempty"`
// An optional template to use for creating resources owned by this
// ProjectDevelopmentStream
Template *ProjectDevelopmentStreamSpecTemplateRef `json:"template,omitempty"`
}

// ProjectDevelopmentStreamStatus defines the observed state of ProjectDevelopmentStream
type ProjectDevelopmentStreamStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Represents the observations of a ProjectDevelopmentStream's current state.
// Known .status.conditions.type are: "TemplateApplied", and "TemplateGenerated"
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

//+kubebuilder:object:root=true
Expand Down
8 changes: 7 additions & 1 deletion api/v1beta1/projectdevelopmentstreamtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// +kubebuilder:pruning:PreserveUnknownFields

type UnstructuredObj struct {
unstructured.Unstructured `json:",inline"`
}

// Settings for a variable to be used to customize the template results
type ProjectDevelopmentStreamTemplateVariable struct {
Expand All @@ -30,7 +36,7 @@ type ProjectDevelopmentStreamTemplateVariable struct {
// Optional default value for use when a value for the variable is not given
// can reference values of other previously defined variables using the Go
// text/template syntax
Default *string `json:"default,omitempty"`
DefaultValue *string `json:"defaultValue,omitempty"`
// Optional description for the variable for display in the UI
Description string `json:"description,omitempty"`
}
Expand Down
59 changes: 50 additions & 9 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 107 additions & 5 deletions config/crd/bases/projctl.konflux.dev_projectdevelopmentstreams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,117 @@ spec:
project:
description: The name of the project this stream belongs to
type: string
resources:
items:
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
template:
description: |-
An optional template to use for creating resources owned by this
ProjectDevelopmentStream
properties:
name:
description: The name of the ProjectDevelopmentStreamTemplate
to use
type: string
values:
description: Values for template variables
items:
description: |-
Provide a value for a variable specified in an associated
ProjectDevelopmentStreamTemplate
properties:
name:
description: The name of the template variable to provide
a value for
type: string
value:
description: The value to be placed in the template variable
type: string
required:
- name
- value
type: object
type: array
required:
- name
type: object
type: object
status:
description: ProjectDevelopmentStreamStatus defines the observed state
of ProjectDevelopmentStream
properties:
conditions:
description: |-
Represents the observations of a ProjectDevelopmentStream's current state.
Known .status.conditions.type are: "TemplateApplied", and "TemplateGenerated"
items:
description: "Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spec:
description: Settings for a variable to be used to customize the
template results
properties:
default:
defaultValue:
description: |-
Optional default value for use when a value for the variable is not given
can reference values of other previously defined variables using the Go
Expand Down
27 changes: 1 addition & 26 deletions config/samples/projctl_v1beta1_projectdevelopmentstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,6 @@ metadata:
app.kubernetes.io/part-of: project-controller
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: project-controller
name: projectdevelopmentstream-sample
name: projectdevelopmentstream-sample-plain
spec:
project: project-sample
resources:
- apiVersion: appstudio.redhat.com/v1alpha1
kind: Application
metadata:
name: "cool-app-version1"
annotations:
pvc.konflux.dev/cloned-from: cool-app1-main
spec:
displayName: "Cool App version1"

- apiVersion: appstudio.redhat.com/v1alpha1
kind: Component
metadata:
name: "cool-comp1-version1"
annotations:
pvc.konflux.dev/cloned-from: cool-comp1-main
spec:
application: "cool-app-version1"
componentName: "cool-comp1-version1"
source:
git:
context: "{cool-comp1-context}"
dockerfileUrl: "{cool-comp1-dockerfileUrl}"
revision: "{cool-comp1-revision}"
url: [email protected]:example/comp1.git
Loading

0 comments on commit 6cf5993

Please sign in to comment.