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

Shipa 2578 pr #238

Merged
merged 10 commits into from
Mar 23, 2022
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
2 changes: 1 addition & 1 deletion ci/limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"github.com/theketchio/ketch/cmd/ketch/output": 68.3,
"github.com/theketchio/ketch/cmd/manager": 0,
"github.com/theketchio/ketch/codeprofile/unit_test_coverage": 0,
"github.com/theketchio/ketch/internal/api/v1beta1": 33.0,
"github.com/theketchio/ketch/internal/api/v1beta1": 32.8,
"github.com/theketchio/ketch/internal/api/v1beta1/mocks": 0,
"github.com/theketchio/ketch/internal/build": 92.3,
"github.com/theketchio/ketch/internal/chart": 67.0,
Expand Down
27 changes: 27 additions & 0 deletions config/crd/bases/theketch.io_apps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2544,8 +2544,35 @@ spec:
description: ServiceAccountName specifies a service account name to
be used for this application.
type: string
type:
description: Type specifies whether an app should be a deployment
or a statefulset
enum:
- Deployment
- StatefulSet
type: string
version:
type: string
volumeClaimTemplates:
description: VolumeClaimTemplates is a list of an app's volumeClaimTemplates
items:
properties:
accessModes:
items:
type: string
type: array
name:
type: string
storage:
type: string
storageClassName:
type: string
required:
- accessModes
- name
- storage
type: object
type: array
required:
- deployments
- framework
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ rules:
- patch
- update
- watch
- apiGroups:
- apps
resources:
- statefulsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- autoscaling
resources:
Expand Down
28 changes: 28 additions & 0 deletions internal/api/v1beta1/app_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ type AppSpec struct {
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
Extensions []runtime.RawExtension `json:"extensions,omitempty"`
// VolumeClaimTemplates is a list of an app's volumeClaimTemplates
VolumeClaimTemplates []PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`

// Type specifies whether an app should be a deployment or a statefulset
// +kubebuilder:validation:default:=Deployment
Type *AppType `json:"type,omitempty"`
}

// +kubebuilder:validation:Enum=Deployment;StatefulSet
type AppType string

const (
DeploymentAppType AppType = "Deployment"
StatefulSetAppType AppType = "StatefulSet"
)

func (spec AppSpec) GetType() AppType {
if spec.Type == nil {
return DeploymentAppType
}
return *spec.Type
}

type PersistentVolumeClaim struct {
Name string `json:"name"`
AccessModes []v1.PersistentVolumeAccessMode `json:"accessModes"`
StorageClassName *string `json:"storageClassName,omitempty"`
Storage string `json:"storage"`
}

// MetadataItem represent a request to add label/annotations to processes
Expand Down
29 changes: 29 additions & 0 deletions internal/api/v1beta1/app_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,3 +1518,32 @@ func TestParseAppReconcileOutcome_Multiple(t *testing.T) {
}
}
}

func TestAppType(t *testing.T) {
at := AppType("NonExistantType")
tt := []struct {
name string
appType *AppType
expected AppType
}{
{
name: "return specified type",
appType: &at,
expected: at,
},
{
name: "type is nil",
appType: nil,
expected: DeploymentAppType,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
as := AppSpec{
Type: tc.appType,
}
appType := as.GetType()
require.Equal(t, tc.expected, appType)
})
}
}
9 changes: 9 additions & 0 deletions internal/chart/application_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type app struct {
ServiceAccountName string `json:"serviceAccountName"`
// SecurityContext specifies security settings for a pod/app, which get applied to all containers.
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
// VolumeClaimTemplates is a list of an app's volumeClaimTemplates
VolumeClaimTemplates []ketchv1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`
// Type specifies whether the app should be a deployment or a statefulset
Type ketchv1.AppType `json:"type"`
}

type deployment struct {
Expand Down Expand Up @@ -133,6 +137,7 @@ func New(application *ketchv1.App, framework *ketchv1.Framework, opts ...Option)
MetadataLabels: application.Spec.Labels,
MetadataAnnotations: application.Spec.Annotations,
ServiceAccountName: application.Spec.ServiceAccountName,
Type: application.Spec.GetType(),
},
IngressController: &framework.Spec.IngressController,
}
Expand All @@ -141,6 +146,10 @@ func New(application *ketchv1.App, framework *ketchv1.Framework, opts ...Option)
values.App.SecurityContext = application.Spec.SecurityContext
}

if application.Spec.VolumeClaimTemplates != nil {
values.App.VolumeClaimTemplates = application.Spec.VolumeClaimTemplates
}

for _, deploymentSpec := range application.Spec.Deployments {
deployment := deployment{
Image: deploymentSpec.Image,
Expand Down
35 changes: 35 additions & 0 deletions internal/chart/application_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ func TestNewApplicationChart(t *testing.T) {
}
return &out
}
setVolumeClaimTemplates := func(app *ketchv1.App) *ketchv1.App {
out := *app
storageClass := "standard"
out.Spec.VolumeClaimTemplates = []ketchv1.PersistentVolumeClaim{
{
Name: "v1-shipa",
AccessModes: []v1.PersistentVolumeAccessMode{"ReadWriteMany"},
StorageClassName: &storageClass,
Storage: "1Gi",
},
{
Name: "v2-shipa",
AccessModes: []v1.PersistentVolumeAccessMode{"ReadWriteOnce"},
StorageClassName: &storageClass,
Storage: "1Gi",
},
}
return &out
}
setStatefulSet := func(app *ketchv1.App) *ketchv1.App {
out := *app
appType := ketchv1.StatefulSetAppType
out.Spec.Type = &appType
return &out
}

tests := []struct {
name string
Expand Down Expand Up @@ -287,6 +312,16 @@ func TestNewApplicationChart(t *testing.T) {
framework: frameworkWithClusterIssuer,
wantYamlsFilename: "dashboard-istio-cluster-issuer-pod-security-context",
},
{
name: "istio templates with cluster issuer and volume claim templates",
opts: []Option{
WithTemplates(templates.IstioDefaultTemplates),
WithExposedPorts(exportedPorts),
},
application: setStatefulSet(setVolumeClaimTemplates(dashboard)),
framework: frameworkWithClusterIssuer,
wantYamlsFilename: "dashboard-istio-cluster-issuer-volume-claim-templates",
},
{
name: "istio templates without cluster issuer",
opts: []Option{
Expand Down
1 change: 0 additions & 1 deletion internal/chart/post_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type postRender struct {
}

func (p *postRender) Run(renderedManifests *bytes.Buffer) (modifiedManifests *bytes.Buffer, err error) {

var configMapList v1.ConfigMapList
opts := &client.ListOptions{Namespace: p.namespace}
if err := p.cli.List(context.Background(), &configMapList, opts); err != nil {
Expand Down
Loading