Skip to content

Commit

Permalink
chore(revert-later): working prototype
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Choudhary <[email protected]>
  • Loading branch information
vishal-chdhry committed Oct 9, 2024
1 parent 1e1ae86 commit d6eb242
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .github/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ nodes:
- containerPort: 443
hostPort: 443
protocol: TCP
extraMounts:
- hostPath: /home/tmp
containerPath: /data/etcd
- role: worker
- role: worker
- role: worker
6 changes: 6 additions & 0 deletions charts/reports-server/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ spec:
args:
{{- if .Values.config.debug }}
- --debug
- --etcdDir=/data/etcd
{{- else }}
- --dbhost={{ include "reports-server.dbHost" . }}
- --dbport={{ include "reports-server.dbPort" . }}
Expand Down Expand Up @@ -92,6 +93,8 @@ spec:
containerPort: 4443
protocol: TCP
volumeMounts:
- mountPath: "/data/etcd"
name: task-pv-storage
- mountPath: /tmp
name: tmp-dir
{{- with .Values.livenessProbe }}
Expand Down Expand Up @@ -119,3 +122,6 @@ spec:
volumes:
- emptyDir: {}
name: tmp-dir
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
14 changes: 14 additions & 0 deletions charts/reports-server/templates/pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: standard
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/data/etcd"
16 changes: 16 additions & 0 deletions charts/reports-server/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
labels:
pv.beta.kubernetes.io/gid: "2000"
spec:
selector:
matchLabels:
{{- include "reports-server.selectorLabels" . | nindent 4 }}
storageClassName: standard
accessModes:
- ReadWriteMany
resources:
requests:
storage: 3Gi
20 changes: 10 additions & 10 deletions charts/reports-server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ podSecurityContext:
# -- Container security context
# @default -- See [values.yaml](values.yaml)
securityContext:
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
privileged: false
allowPrivilegeEscalation: false
seccompProfile:
type: RuntimeDefault
# capabilities:
# drop:
# - ALL
readOnlyRootFilesystem: false
# runAsNonRoot: true
runAsUser: 0
privileged: true
allowPrivilegeEscalation: true
# seccompProfile:
# type: RuntimeDefault

# -- Liveness probe
livenessProbe:
Expand Down
33 changes: 33 additions & 0 deletions config/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ data:
postgres-password: "cmVwb3J0cw=="
# We don't auto-generate LDAP password when it's not provided as we do for other passwords
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down Expand Up @@ -312,6 +339,10 @@ spec:
serviceAccountName: reports-server
securityContext:
fsGroup: 2000
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: reports-server
args:
Expand Down Expand Up @@ -345,6 +376,8 @@ spec:
containerPort: 4443
protocol: TCP
volumeMounts:
- mountPath: "/data/etcd"
name: task-pv-storage
- mountPath: /tmp
name: tmp-dir
livenessProbe:
Expand Down
1 change: 1 addition & 0 deletions pkg/app/policyserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func runCommand(o *opts.Options, stopCh <-chan struct{}) error {

if o.Debug {
go func() {
klog.InfoS("starting embedded etcd etcd in directory=%s", o.EtcdDir)
err := etcd.StartETCDServer(stopCh, o.EtcdDir)
if err != nil {
klog.ErrorS(err, "failed to start etcd server")
Expand Down
14 changes: 12 additions & 2 deletions pkg/storage/etcd/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
)

type ObjectStorageNamespaced[T metav1.Object] interface {
Expand Down Expand Up @@ -57,13 +58,16 @@ func (o *objectStoreNamespaced[T]) Get(ctx context.Context, name, namespace stri
key := o.getKey(name, namespace)
resp, err := o.etcdclient.Get(ctx, key)
if err != nil {
klog.ErrorS(err, "failed to get report kind=%s", o.gvk.String())
return obj, err

Check warning on line 62 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L57-L62

Added lines #L57 - L62 were not covered by tests
}
klog.InfoS("get resp resp=%+v", resp)
if len(resp.Kvs) != 1 {
return obj, errors.NewNotFound(o.gr, key)

Check warning on line 66 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L64-L66

Added lines #L64 - L66 were not covered by tests
}
err = json.Unmarshal(resp.Kvs[0].Value, obj)
err = json.Unmarshal(resp.Kvs[0].Value, &obj)
if err != nil {
klog.ErrorS(err, "failed to marshal report kind=%s", o.gvk.String())
return obj, errors.NewNotFound(o.gr, key)

Check warning on line 71 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L68-L71

Added lines #L68 - L71 were not covered by tests
}
return obj, nil

Check warning on line 73 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L73

Added line #L73 was not covered by tests
Expand All @@ -77,15 +81,17 @@ func (o *objectStoreNamespaced[T]) List(ctx context.Context, namespace string) (
key := o.getPrefix()
resp, err := o.etcdclient.Get(ctx, key, clientv3.WithPrefix())
if err != nil {
klog.ErrorS(err, "failed to list report kind=%s", o.gvk.String())
return objects, err

Check warning on line 85 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L80-L85

Added lines #L80 - L85 were not covered by tests
}
klog.InfoS("list resp resp=%+v", resp)
if len(resp.Kvs) == 0 {
return objects, errors.NewNotFound(o.gr, key)

Check warning on line 89 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L87-L89

Added lines #L87 - L89 were not covered by tests
}
objects = make([]T, 0, len(resp.Kvs))
for _, v := range resp.Kvs {
var obj T
err = json.Unmarshal(v.Value, obj)
err = json.Unmarshal(v.Value, &obj)
if err != nil {
return objects, errors.NewNotFound(o.gr, key)

Check warning on line 96 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L91-L96

Added lines #L91 - L96 were not covered by tests
}
Expand All @@ -101,8 +107,10 @@ func (o *objectStoreNamespaced[T]) Create(ctx context.Context, obj T) error {
key := o.getKey(obj.GetName(), obj.GetNamespace())
resp, err := o.etcdclient.Get(ctx, key)
if err != nil {
klog.ErrorS(err, "failed to create report kind=%s", o.gvk.String())
return err

Check warning on line 111 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L107-L111

Added lines #L107 - L111 were not covered by tests
}
klog.InfoS("create resp resp=%+v", resp)
if len(resp.Kvs) > 0 {
return errors.NewAlreadyExists(o.gr, key)

Check warning on line 115 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L113-L115

Added lines #L113 - L115 were not covered by tests
}
Expand All @@ -126,6 +134,7 @@ func (o *objectStoreNamespaced[T]) Update(ctx context.Context, obj T) error {
key := o.getKey(obj.GetName(), obj.GetNamespace())
resp, err := o.etcdclient.Get(ctx, key)
if err != nil {
klog.ErrorS(err, "failed to update report kind=%s", o.gvk.String())
return err

Check warning on line 138 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L134-L138

Added lines #L134 - L138 were not covered by tests
}
if len(resp.Kvs) != 1 {
Expand All @@ -151,6 +160,7 @@ func (o *objectStoreNamespaced[T]) Delete(ctx context.Context, name, namespace s
key := o.getKey(name, namespace)
resp, err := o.etcdclient.Delete(ctx, key)
if err != nil {
klog.ErrorS(err, "failed to delete report kind=%s", o.gvk.String())
return err

Check warning on line 164 in pkg/storage/etcd/store.go

View check run for this annotation

Codecov / codecov/patch

pkg/storage/etcd/store.go#L160-L164

Added lines #L160 - L164 were not covered by tests
}
if resp.Deleted == 0 {
Expand Down

0 comments on commit d6eb242

Please sign in to comment.