pepr 0.46.3-nightly.7 → 0.46.3-nightly.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli.js +556 -554
- package/dist/controller.js +1 -1
- package/dist/lib/assets/assets.d.ts +3 -2
- package/dist/lib/assets/assets.d.ts.map +1 -1
- package/dist/lib/assets/envrionment.d.ts +4 -0
- package/dist/lib/assets/envrionment.d.ts.map +1 -0
- package/dist/lib/assets/pods.d.ts +1 -3
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/yaml/overridesFile.d.ts +1 -2
- package/dist/lib/assets/yaml/overridesFile.d.ts.map +1 -1
- package/dist/lib/filter/adjudication.d.ts +22 -0
- package/dist/lib/filter/adjudication.d.ts.map +1 -0
- package/dist/lib/filter/filter.d.ts +0 -19
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib.js +229 -229
- package/dist/lib.js.map +4 -4
- package/package.json +1 -1
- package/src/cli/build.helpers.ts +3 -2
- package/src/cli/init/templates.ts +2 -2
- package/src/lib/assets/assets.ts +24 -5
- package/src/lib/assets/envrionment.ts +26 -0
- package/src/lib/assets/pods.ts +2 -26
- package/src/lib/assets/yaml/overridesFile.ts +2 -3
- package/src/lib/filter/adjudication.ts +196 -0
- package/src/lib/filter/filter.ts +20 -194
- package/src/lib/types.ts +1 -0
package/dist/cli.js
CHANGED
|
@@ -433,8 +433,25 @@ async function createDirectoryIfNotExists(path) {
|
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
// src/lib/assets/
|
|
437
|
-
|
|
436
|
+
// src/lib/assets/envrionment.ts
|
|
437
|
+
function genEnv(config, watchMode = false, ignoreWatchMode = false) {
|
|
438
|
+
const noWatchDef = {
|
|
439
|
+
PEPR_PRETTY_LOG: "false",
|
|
440
|
+
LOG_LEVEL: config.logLevel || "info"
|
|
441
|
+
};
|
|
442
|
+
const def = {
|
|
443
|
+
PEPR_WATCH_MODE: watchMode ? "true" : "false",
|
|
444
|
+
...noWatchDef
|
|
445
|
+
};
|
|
446
|
+
if (config.env && config.env["PEPR_WATCH_MODE"]) {
|
|
447
|
+
delete config.env["PEPR_WATCH_MODE"];
|
|
448
|
+
}
|
|
449
|
+
const cfg = config.env || {};
|
|
450
|
+
return ignoreWatchMode ? Object.entries({ ...noWatchDef, ...cfg }).map(([name2, value]) => ({ name: name2, value })) : Object.entries({ ...def, ...cfg }).map(([name2, value]) => ({ name: name2, value }));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/lib/assets/yaml/overridesFile.ts
|
|
454
|
+
var import_client_node = require("@kubernetes/client-node");
|
|
438
455
|
|
|
439
456
|
// src/lib/telemetry/logger.ts
|
|
440
457
|
var import_pino = require("pino");
|
|
@@ -631,500 +648,152 @@ function replaceString(str, stringA, stringB) {
|
|
|
631
648
|
return str.replace(regExp, stringB);
|
|
632
649
|
}
|
|
633
650
|
|
|
634
|
-
// src/lib/assets/
|
|
635
|
-
function
|
|
636
|
-
|
|
651
|
+
// src/lib/assets/rbac.ts
|
|
652
|
+
function clusterRole(name2, capabilities, rbacMode = "admin", customRbac) {
|
|
653
|
+
const rbacMap = createRBACMap(capabilities);
|
|
654
|
+
const scopedRules = Object.keys(rbacMap).map((key) => {
|
|
655
|
+
const group2 = key.split("/").length < 3 ? "" : key.split("/")[0];
|
|
637
656
|
return {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
name: "pepr-system",
|
|
642
|
-
labels: namespaceLabels ?? {}
|
|
643
|
-
}
|
|
657
|
+
apiGroups: [group2],
|
|
658
|
+
resources: [rbacMap[key].plural],
|
|
659
|
+
verbs: rbacMap[key].verbs
|
|
644
660
|
};
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
661
|
+
});
|
|
662
|
+
const mergedRBAC = [...Array.isArray(customRbac) ? customRbac : [], ...scopedRules];
|
|
663
|
+
const deduper = {};
|
|
664
|
+
mergedRBAC.forEach((rule) => {
|
|
665
|
+
const key = `${rule.apiGroups}/${rule.resources}`;
|
|
666
|
+
if (deduper[key]) {
|
|
667
|
+
deduper[key].verbs = Array.from(/* @__PURE__ */ new Set([...deduper[key].verbs, ...rule.verbs]));
|
|
668
|
+
} else {
|
|
669
|
+
deduper[key] = { ...rule, verbs: rule.verbs || [] };
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
const deduplicatedRules = Object.values(deduper);
|
|
673
|
+
return {
|
|
674
|
+
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
675
|
+
kind: "ClusterRole",
|
|
676
|
+
metadata: { name: name2 },
|
|
677
|
+
rules: rbacMode === "scoped" ? deduplicatedRules : [
|
|
678
|
+
{
|
|
679
|
+
apiGroups: ["*"],
|
|
680
|
+
resources: ["*"],
|
|
681
|
+
verbs: ["create", "delete", "get", "list", "patch", "update", "watch"]
|
|
651
682
|
}
|
|
652
|
-
|
|
653
|
-
}
|
|
683
|
+
]
|
|
684
|
+
};
|
|
654
685
|
}
|
|
655
|
-
function
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
686
|
+
function clusterRoleBinding(name2) {
|
|
687
|
+
return {
|
|
688
|
+
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
689
|
+
kind: "ClusterRoleBinding",
|
|
690
|
+
metadata: { name: name2 },
|
|
691
|
+
roleRef: {
|
|
692
|
+
apiGroup: "rbac.authorization.k8s.io",
|
|
693
|
+
kind: "ClusterRole",
|
|
694
|
+
name: name2
|
|
695
|
+
},
|
|
696
|
+
subjects: [
|
|
697
|
+
{
|
|
698
|
+
kind: "ServiceAccount",
|
|
699
|
+
name: name2,
|
|
700
|
+
namespace: "pepr-system"
|
|
701
|
+
}
|
|
702
|
+
]
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function serviceAccount(name2) {
|
|
706
|
+
return {
|
|
707
|
+
apiVersion: "v1",
|
|
708
|
+
kind: "ServiceAccount",
|
|
673
709
|
metadata: {
|
|
674
|
-
name:
|
|
675
|
-
namespace: "pepr-system"
|
|
710
|
+
name: name2,
|
|
711
|
+
namespace: "pepr-system"
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function storeRole(name2) {
|
|
716
|
+
name2 = `${name2}-store`;
|
|
717
|
+
return {
|
|
718
|
+
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
719
|
+
kind: "Role",
|
|
720
|
+
metadata: { name: name2, namespace: "pepr-system" },
|
|
721
|
+
rules: [
|
|
722
|
+
{
|
|
723
|
+
apiGroups: ["pepr.dev"],
|
|
724
|
+
resources: ["peprstores"],
|
|
725
|
+
resourceNames: [""],
|
|
726
|
+
verbs: ["create", "get", "patch", "watch"]
|
|
727
|
+
}
|
|
728
|
+
]
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function storeRoleBinding(name2) {
|
|
732
|
+
name2 = `${name2}-store`;
|
|
733
|
+
return {
|
|
734
|
+
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
735
|
+
kind: "RoleBinding",
|
|
736
|
+
metadata: { name: name2, namespace: "pepr-system" },
|
|
737
|
+
roleRef: {
|
|
738
|
+
apiGroup: "rbac.authorization.k8s.io",
|
|
739
|
+
kind: "Role",
|
|
740
|
+
name: name2
|
|
741
|
+
},
|
|
742
|
+
subjects: [
|
|
743
|
+
{
|
|
744
|
+
kind: "ServiceAccount",
|
|
745
|
+
name: name2,
|
|
746
|
+
namespace: "pepr-system"
|
|
747
|
+
}
|
|
748
|
+
]
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// src/lib/assets/yaml/overridesFile.ts
|
|
753
|
+
var import_fs2 = require("fs");
|
|
754
|
+
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path, imagePullSecrets) {
|
|
755
|
+
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
756
|
+
const overrides = {
|
|
757
|
+
imagePullSecrets,
|
|
758
|
+
additionalIgnoredNamespaces: [],
|
|
759
|
+
rbac: rbacOverrides,
|
|
760
|
+
secrets: {
|
|
761
|
+
apiPath: Buffer.from(apiPath).toString("base64")
|
|
762
|
+
},
|
|
763
|
+
hash,
|
|
764
|
+
namespace: {
|
|
765
|
+
annotations: {},
|
|
766
|
+
labels: config.customLabels?.namespace ?? {
|
|
767
|
+
"pepr.dev": ""
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
uuid: name2,
|
|
771
|
+
admission: {
|
|
772
|
+
terminationGracePeriodSeconds: 5,
|
|
773
|
+
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
774
|
+
webhookTimeout: config.webhookTimeout,
|
|
775
|
+
env: genEnv(config, false, true),
|
|
776
|
+
envFrom: [],
|
|
777
|
+
image,
|
|
676
778
|
annotations: {
|
|
677
|
-
"pepr.dev/description": config.description || ""
|
|
779
|
+
"pepr.dev/description": `${config.description}` || ""
|
|
678
780
|
},
|
|
679
781
|
labels: {
|
|
680
|
-
app,
|
|
681
|
-
"pepr.dev/controller": "
|
|
782
|
+
app: name2,
|
|
783
|
+
"pepr.dev/controller": "admission",
|
|
682
784
|
"pepr.dev/uuid": config.uuid
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
spec: {
|
|
686
|
-
replicas: 1,
|
|
687
|
-
strategy: {
|
|
688
|
-
type: "Recreate"
|
|
689
785
|
},
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
786
|
+
securityContext: {
|
|
787
|
+
runAsUser: 65532,
|
|
788
|
+
runAsGroup: 65532,
|
|
789
|
+
runAsNonRoot: true,
|
|
790
|
+
fsGroup: 65532
|
|
695
791
|
},
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
labels: {
|
|
702
|
-
app,
|
|
703
|
-
"pepr.dev/controller": "watcher"
|
|
704
|
-
}
|
|
705
|
-
},
|
|
706
|
-
spec: {
|
|
707
|
-
terminationGracePeriodSeconds: 5,
|
|
708
|
-
serviceAccountName: name2,
|
|
709
|
-
securityContext: {
|
|
710
|
-
runAsUser: 65532,
|
|
711
|
-
runAsGroup: 65532,
|
|
712
|
-
runAsNonRoot: true,
|
|
713
|
-
fsGroup: 65532
|
|
714
|
-
},
|
|
715
|
-
containers: [
|
|
716
|
-
{
|
|
717
|
-
name: "watcher",
|
|
718
|
-
image,
|
|
719
|
-
imagePullPolicy: "IfNotPresent",
|
|
720
|
-
args: ["/app/node_modules/pepr/dist/controller.js", hash],
|
|
721
|
-
readinessProbe: {
|
|
722
|
-
httpGet: {
|
|
723
|
-
path: "/healthz",
|
|
724
|
-
port: 3e3,
|
|
725
|
-
scheme: "HTTPS"
|
|
726
|
-
},
|
|
727
|
-
initialDelaySeconds: 10
|
|
728
|
-
},
|
|
729
|
-
livenessProbe: {
|
|
730
|
-
httpGet: {
|
|
731
|
-
path: "/healthz",
|
|
732
|
-
port: 3e3,
|
|
733
|
-
scheme: "HTTPS"
|
|
734
|
-
},
|
|
735
|
-
initialDelaySeconds: 10
|
|
736
|
-
},
|
|
737
|
-
ports: [
|
|
738
|
-
{
|
|
739
|
-
containerPort: 3e3
|
|
740
|
-
}
|
|
741
|
-
],
|
|
742
|
-
resources: {
|
|
743
|
-
requests: {
|
|
744
|
-
memory: "256Mi",
|
|
745
|
-
cpu: "200m"
|
|
746
|
-
},
|
|
747
|
-
limits: {
|
|
748
|
-
memory: "512Mi",
|
|
749
|
-
cpu: "500m"
|
|
750
|
-
}
|
|
751
|
-
},
|
|
752
|
-
securityContext: {
|
|
753
|
-
runAsUser: 65532,
|
|
754
|
-
runAsGroup: 65532,
|
|
755
|
-
runAsNonRoot: true,
|
|
756
|
-
allowPrivilegeEscalation: false,
|
|
757
|
-
capabilities: {
|
|
758
|
-
drop: ["ALL"]
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
volumeMounts: [
|
|
762
|
-
{
|
|
763
|
-
name: "tls-certs",
|
|
764
|
-
mountPath: "/etc/certs",
|
|
765
|
-
readOnly: true
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
name: "module",
|
|
769
|
-
mountPath: `/app/load`,
|
|
770
|
-
readOnly: true
|
|
771
|
-
}
|
|
772
|
-
],
|
|
773
|
-
env: genEnv(config, true)
|
|
774
|
-
}
|
|
775
|
-
],
|
|
776
|
-
volumes: [
|
|
777
|
-
{
|
|
778
|
-
name: "tls-certs",
|
|
779
|
-
secret: {
|
|
780
|
-
secretName: `${name2}-tls`
|
|
781
|
-
}
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
name: "module",
|
|
785
|
-
secret: {
|
|
786
|
-
secretName: `${name2}-module`
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
]
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
if (imagePullSecret) {
|
|
795
|
-
deploy.spec.template.spec.imagePullSecrets = [{ name: imagePullSecret }];
|
|
796
|
-
}
|
|
797
|
-
return deploy;
|
|
798
|
-
}
|
|
799
|
-
function getDeployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
800
|
-
const { name: name2, image, config } = assets;
|
|
801
|
-
const app = name2;
|
|
802
|
-
const deploy = {
|
|
803
|
-
apiVersion: "apps/v1",
|
|
804
|
-
kind: "Deployment",
|
|
805
|
-
metadata: {
|
|
806
|
-
name: name2,
|
|
807
|
-
namespace: "pepr-system",
|
|
808
|
-
annotations: {
|
|
809
|
-
"pepr.dev/description": config.description || ""
|
|
810
|
-
},
|
|
811
|
-
labels: {
|
|
812
|
-
app,
|
|
813
|
-
"pepr.dev/controller": "admission",
|
|
814
|
-
"pepr.dev/uuid": config.uuid
|
|
815
|
-
}
|
|
816
|
-
},
|
|
817
|
-
spec: {
|
|
818
|
-
replicas: 2,
|
|
819
|
-
selector: {
|
|
820
|
-
matchLabels: {
|
|
821
|
-
app,
|
|
822
|
-
"pepr.dev/controller": "admission"
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
template: {
|
|
826
|
-
metadata: {
|
|
827
|
-
annotations: {
|
|
828
|
-
buildTimestamp: `${buildTimestamp}`
|
|
829
|
-
},
|
|
830
|
-
labels: {
|
|
831
|
-
app,
|
|
832
|
-
"pepr.dev/controller": "admission"
|
|
833
|
-
}
|
|
834
|
-
},
|
|
835
|
-
spec: {
|
|
836
|
-
terminationGracePeriodSeconds: 5,
|
|
837
|
-
priorityClassName: "system-node-critical",
|
|
838
|
-
serviceAccountName: name2,
|
|
839
|
-
securityContext: {
|
|
840
|
-
runAsUser: 65532,
|
|
841
|
-
runAsGroup: 65532,
|
|
842
|
-
runAsNonRoot: true,
|
|
843
|
-
fsGroup: 65532
|
|
844
|
-
},
|
|
845
|
-
containers: [
|
|
846
|
-
{
|
|
847
|
-
name: "server",
|
|
848
|
-
image,
|
|
849
|
-
imagePullPolicy: "IfNotPresent",
|
|
850
|
-
args: ["/app/node_modules/pepr/dist/controller.js", hash],
|
|
851
|
-
readinessProbe: {
|
|
852
|
-
httpGet: {
|
|
853
|
-
path: "/healthz",
|
|
854
|
-
port: 3e3,
|
|
855
|
-
scheme: "HTTPS"
|
|
856
|
-
},
|
|
857
|
-
initialDelaySeconds: 10
|
|
858
|
-
},
|
|
859
|
-
livenessProbe: {
|
|
860
|
-
httpGet: {
|
|
861
|
-
path: "/healthz",
|
|
862
|
-
port: 3e3,
|
|
863
|
-
scheme: "HTTPS"
|
|
864
|
-
},
|
|
865
|
-
initialDelaySeconds: 10
|
|
866
|
-
},
|
|
867
|
-
ports: [
|
|
868
|
-
{
|
|
869
|
-
containerPort: 3e3
|
|
870
|
-
}
|
|
871
|
-
],
|
|
872
|
-
resources: {
|
|
873
|
-
requests: {
|
|
874
|
-
memory: "256Mi",
|
|
875
|
-
cpu: "200m"
|
|
876
|
-
},
|
|
877
|
-
limits: {
|
|
878
|
-
memory: "512Mi",
|
|
879
|
-
cpu: "500m"
|
|
880
|
-
}
|
|
881
|
-
},
|
|
882
|
-
env: genEnv(config),
|
|
883
|
-
securityContext: {
|
|
884
|
-
runAsUser: 65532,
|
|
885
|
-
runAsGroup: 65532,
|
|
886
|
-
runAsNonRoot: true,
|
|
887
|
-
allowPrivilegeEscalation: false,
|
|
888
|
-
capabilities: {
|
|
889
|
-
drop: ["ALL"]
|
|
890
|
-
}
|
|
891
|
-
},
|
|
892
|
-
volumeMounts: [
|
|
893
|
-
{
|
|
894
|
-
name: "tls-certs",
|
|
895
|
-
mountPath: "/etc/certs",
|
|
896
|
-
readOnly: true
|
|
897
|
-
},
|
|
898
|
-
{
|
|
899
|
-
name: "api-path",
|
|
900
|
-
mountPath: "/app/api-path",
|
|
901
|
-
readOnly: true
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
name: "module",
|
|
905
|
-
mountPath: `/app/load`,
|
|
906
|
-
readOnly: true
|
|
907
|
-
}
|
|
908
|
-
]
|
|
909
|
-
}
|
|
910
|
-
],
|
|
911
|
-
volumes: [
|
|
912
|
-
{
|
|
913
|
-
name: "tls-certs",
|
|
914
|
-
secret: {
|
|
915
|
-
secretName: `${name2}-tls`
|
|
916
|
-
}
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
name: "api-path",
|
|
920
|
-
secret: {
|
|
921
|
-
secretName: `${name2}-api-path`
|
|
922
|
-
}
|
|
923
|
-
},
|
|
924
|
-
{
|
|
925
|
-
name: "module",
|
|
926
|
-
secret: {
|
|
927
|
-
secretName: `${name2}-module`
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
]
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
if (imagePullSecret) {
|
|
936
|
-
deploy.spec.template.spec.imagePullSecrets = [{ name: imagePullSecret }];
|
|
937
|
-
}
|
|
938
|
-
return deploy;
|
|
939
|
-
}
|
|
940
|
-
function getModuleSecret(name2, data, hash) {
|
|
941
|
-
const compressed = (0, import_zlib.gzipSync)(data);
|
|
942
|
-
const path = `module-${hash}.js.gz`;
|
|
943
|
-
const compressedData = compressed.toString("base64");
|
|
944
|
-
if (secretOverLimit(compressedData)) {
|
|
945
|
-
const error = new Error(`Module secret for ${name2} is over the 1MB limit`);
|
|
946
|
-
console.error("Uncaught Exception:", error);
|
|
947
|
-
process.exit(1);
|
|
948
|
-
} else {
|
|
949
|
-
return {
|
|
950
|
-
apiVersion: "v1",
|
|
951
|
-
kind: "Secret",
|
|
952
|
-
metadata: {
|
|
953
|
-
name: `${name2}-module`,
|
|
954
|
-
namespace: "pepr-system"
|
|
955
|
-
},
|
|
956
|
-
type: "Opaque",
|
|
957
|
-
data: {
|
|
958
|
-
[path]: compressed.toString("base64")
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
function genEnv(config, watchMode = false, ignoreWatchMode = false) {
|
|
964
|
-
const noWatchDef = {
|
|
965
|
-
PEPR_PRETTY_LOG: "false",
|
|
966
|
-
LOG_LEVEL: config.logLevel || "info"
|
|
967
|
-
};
|
|
968
|
-
const def = {
|
|
969
|
-
PEPR_WATCH_MODE: watchMode ? "true" : "false",
|
|
970
|
-
...noWatchDef
|
|
971
|
-
};
|
|
972
|
-
if (config.env && config.env["PEPR_WATCH_MODE"]) {
|
|
973
|
-
delete config.env["PEPR_WATCH_MODE"];
|
|
974
|
-
}
|
|
975
|
-
const cfg = config.env || {};
|
|
976
|
-
return ignoreWatchMode ? Object.entries({ ...noWatchDef, ...cfg }).map(([name2, value]) => ({ name: name2, value })) : Object.entries({ ...def, ...cfg }).map(([name2, value]) => ({ name: name2, value }));
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
// src/lib/assets/yaml/overridesFile.ts
|
|
980
|
-
var import_client_node = require("@kubernetes/client-node");
|
|
981
|
-
|
|
982
|
-
// src/lib/assets/rbac.ts
|
|
983
|
-
function clusterRole(name2, capabilities, rbacMode = "admin", customRbac) {
|
|
984
|
-
const rbacMap = createRBACMap(capabilities);
|
|
985
|
-
const scopedRules = Object.keys(rbacMap).map((key) => {
|
|
986
|
-
const group2 = key.split("/").length < 3 ? "" : key.split("/")[0];
|
|
987
|
-
return {
|
|
988
|
-
apiGroups: [group2],
|
|
989
|
-
resources: [rbacMap[key].plural],
|
|
990
|
-
verbs: rbacMap[key].verbs
|
|
991
|
-
};
|
|
992
|
-
});
|
|
993
|
-
const mergedRBAC = [...Array.isArray(customRbac) ? customRbac : [], ...scopedRules];
|
|
994
|
-
const deduper = {};
|
|
995
|
-
mergedRBAC.forEach((rule) => {
|
|
996
|
-
const key = `${rule.apiGroups}/${rule.resources}`;
|
|
997
|
-
if (deduper[key]) {
|
|
998
|
-
deduper[key].verbs = Array.from(/* @__PURE__ */ new Set([...deduper[key].verbs, ...rule.verbs]));
|
|
999
|
-
} else {
|
|
1000
|
-
deduper[key] = { ...rule, verbs: rule.verbs || [] };
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
const deduplicatedRules = Object.values(deduper);
|
|
1004
|
-
return {
|
|
1005
|
-
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
1006
|
-
kind: "ClusterRole",
|
|
1007
|
-
metadata: { name: name2 },
|
|
1008
|
-
rules: rbacMode === "scoped" ? deduplicatedRules : [
|
|
1009
|
-
{
|
|
1010
|
-
apiGroups: ["*"],
|
|
1011
|
-
resources: ["*"],
|
|
1012
|
-
verbs: ["create", "delete", "get", "list", "patch", "update", "watch"]
|
|
1013
|
-
}
|
|
1014
|
-
]
|
|
1015
|
-
};
|
|
1016
|
-
}
|
|
1017
|
-
function clusterRoleBinding(name2) {
|
|
1018
|
-
return {
|
|
1019
|
-
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
1020
|
-
kind: "ClusterRoleBinding",
|
|
1021
|
-
metadata: { name: name2 },
|
|
1022
|
-
roleRef: {
|
|
1023
|
-
apiGroup: "rbac.authorization.k8s.io",
|
|
1024
|
-
kind: "ClusterRole",
|
|
1025
|
-
name: name2
|
|
1026
|
-
},
|
|
1027
|
-
subjects: [
|
|
1028
|
-
{
|
|
1029
|
-
kind: "ServiceAccount",
|
|
1030
|
-
name: name2,
|
|
1031
|
-
namespace: "pepr-system"
|
|
1032
|
-
}
|
|
1033
|
-
]
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
function serviceAccount(name2) {
|
|
1037
|
-
return {
|
|
1038
|
-
apiVersion: "v1",
|
|
1039
|
-
kind: "ServiceAccount",
|
|
1040
|
-
metadata: {
|
|
1041
|
-
name: name2,
|
|
1042
|
-
namespace: "pepr-system"
|
|
1043
|
-
}
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function storeRole(name2) {
|
|
1047
|
-
name2 = `${name2}-store`;
|
|
1048
|
-
return {
|
|
1049
|
-
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
1050
|
-
kind: "Role",
|
|
1051
|
-
metadata: { name: name2, namespace: "pepr-system" },
|
|
1052
|
-
rules: [
|
|
1053
|
-
{
|
|
1054
|
-
apiGroups: ["pepr.dev"],
|
|
1055
|
-
resources: ["peprstores"],
|
|
1056
|
-
resourceNames: [""],
|
|
1057
|
-
verbs: ["create", "get", "patch", "watch"]
|
|
1058
|
-
}
|
|
1059
|
-
]
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
function storeRoleBinding(name2) {
|
|
1063
|
-
name2 = `${name2}-store`;
|
|
1064
|
-
return {
|
|
1065
|
-
apiVersion: "rbac.authorization.k8s.io/v1",
|
|
1066
|
-
kind: "RoleBinding",
|
|
1067
|
-
metadata: { name: name2, namespace: "pepr-system" },
|
|
1068
|
-
roleRef: {
|
|
1069
|
-
apiGroup: "rbac.authorization.k8s.io",
|
|
1070
|
-
kind: "Role",
|
|
1071
|
-
name: name2
|
|
1072
|
-
},
|
|
1073
|
-
subjects: [
|
|
1074
|
-
{
|
|
1075
|
-
kind: "ServiceAccount",
|
|
1076
|
-
name: name2,
|
|
1077
|
-
namespace: "pepr-system"
|
|
1078
|
-
}
|
|
1079
|
-
]
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
// src/lib/assets/yaml/overridesFile.ts
|
|
1084
|
-
var import_fs2 = require("fs");
|
|
1085
|
-
async function overridesFile({ hash, name: name2, image, config, apiPath, capabilities }, path, imagePullSecrets) {
|
|
1086
|
-
const rbacOverrides = clusterRole(name2, capabilities, config.rbacMode, config.rbac).rules;
|
|
1087
|
-
const overrides = {
|
|
1088
|
-
imagePullSecrets,
|
|
1089
|
-
additionalIgnoredNamespaces: [],
|
|
1090
|
-
rbac: rbacOverrides,
|
|
1091
|
-
secrets: {
|
|
1092
|
-
apiPath: Buffer.from(apiPath).toString("base64")
|
|
1093
|
-
},
|
|
1094
|
-
hash,
|
|
1095
|
-
namespace: {
|
|
1096
|
-
annotations: {},
|
|
1097
|
-
labels: config.customLabels?.namespace ?? {
|
|
1098
|
-
"pepr.dev": ""
|
|
1099
|
-
}
|
|
1100
|
-
},
|
|
1101
|
-
uuid: name2,
|
|
1102
|
-
admission: {
|
|
1103
|
-
terminationGracePeriodSeconds: 5,
|
|
1104
|
-
failurePolicy: config.onError === "reject" ? "Fail" : "Ignore",
|
|
1105
|
-
webhookTimeout: config.webhookTimeout,
|
|
1106
|
-
env: genEnv(config, false, true),
|
|
1107
|
-
envFrom: [],
|
|
1108
|
-
image,
|
|
1109
|
-
annotations: {
|
|
1110
|
-
"pepr.dev/description": `${config.description}` || ""
|
|
1111
|
-
},
|
|
1112
|
-
labels: {
|
|
1113
|
-
app: name2,
|
|
1114
|
-
"pepr.dev/controller": "admission",
|
|
1115
|
-
"pepr.dev/uuid": config.uuid
|
|
1116
|
-
},
|
|
1117
|
-
securityContext: {
|
|
1118
|
-
runAsUser: 65532,
|
|
1119
|
-
runAsGroup: 65532,
|
|
1120
|
-
runAsNonRoot: true,
|
|
1121
|
-
fsGroup: 65532
|
|
1122
|
-
},
|
|
1123
|
-
readinessProbe: {
|
|
1124
|
-
httpGet: {
|
|
1125
|
-
path: "/healthz",
|
|
1126
|
-
port: 3e3,
|
|
1127
|
-
scheme: "HTTPS"
|
|
792
|
+
readinessProbe: {
|
|
793
|
+
httpGet: {
|
|
794
|
+
path: "/healthz",
|
|
795
|
+
port: 3e3,
|
|
796
|
+
scheme: "HTTPS"
|
|
1128
797
|
},
|
|
1129
798
|
initialDelaySeconds: 10
|
|
1130
799
|
},
|
|
@@ -1458,7 +1127,7 @@ var Assets = class {
|
|
|
1458
1127
|
}
|
|
1459
1128
|
zarfYaml = (zarfYamlGenerator, path) => zarfYamlGenerator(this, path, "manifests");
|
|
1460
1129
|
zarfYamlChart = (zarfYamlGenerator, path) => zarfYamlGenerator(this, path, "charts");
|
|
1461
|
-
allYaml = async (yamlGenerationFunction, imagePullSecret) => {
|
|
1130
|
+
allYaml = async (yamlGenerationFunction, getDeploymentFunction, getWatcherFunction, imagePullSecret) => {
|
|
1462
1131
|
this.capabilities = await loadCapabilities(this.path);
|
|
1463
1132
|
for (const capability of this.capabilities) {
|
|
1464
1133
|
namespaceComplianceValidator(capability, this.alwaysIgnore?.namespaces);
|
|
@@ -1466,8 +1135,8 @@ var Assets = class {
|
|
|
1466
1135
|
const code = await import_fs3.promises.readFile(this.path);
|
|
1467
1136
|
const moduleHash = import_crypto.default.createHash("sha256").update(code).digest("hex");
|
|
1468
1137
|
const deployments = {
|
|
1469
|
-
default:
|
|
1470
|
-
watch:
|
|
1138
|
+
default: getDeploymentFunction(this, moduleHash, this.buildTimestamp, imagePullSecret),
|
|
1139
|
+
watch: getWatcherFunction(this, moduleHash, this.buildTimestamp, imagePullSecret)
|
|
1471
1140
|
};
|
|
1472
1141
|
return yamlGenerationFunction(this, deployments);
|
|
1473
1142
|
};
|
|
@@ -1495,7 +1164,7 @@ var Assets = class {
|
|
|
1495
1164
|
);
|
|
1496
1165
|
}
|
|
1497
1166
|
};
|
|
1498
|
-
generateHelmChart = async (webhookGeneratorFunction, basePath) => {
|
|
1167
|
+
generateHelmChart = async (webhookGeneratorFunction, getWatcherFunction, getModuleSecretFunction, basePath) => {
|
|
1499
1168
|
const helm = helmLayout(basePath, this.config.uuid);
|
|
1500
1169
|
try {
|
|
1501
1170
|
await Promise.all(
|
|
@@ -1523,7 +1192,7 @@ var Assets = class {
|
|
|
1523
1192
|
[helm.files.serviceAccountYaml, () => toYaml(serviceAccount(this.name))],
|
|
1524
1193
|
[
|
|
1525
1194
|
helm.files.moduleSecretYaml,
|
|
1526
|
-
() => toYaml(
|
|
1195
|
+
() => toYaml(getModuleSecretFunction(this.name, code, moduleHash))
|
|
1527
1196
|
]
|
|
1528
1197
|
];
|
|
1529
1198
|
await Promise.all(pairs.map(async ([file, content]) => await import_fs3.promises.writeFile(file, content())));
|
|
@@ -1549,7 +1218,7 @@ var Assets = class {
|
|
|
1549
1218
|
)
|
|
1550
1219
|
};
|
|
1551
1220
|
await this.writeWebhookFiles(webhooks.validate, webhooks.mutate, helm);
|
|
1552
|
-
const watchDeployment =
|
|
1221
|
+
const watchDeployment = getWatcherFunction(this, moduleHash, this.buildTimestamp);
|
|
1553
1222
|
if (watchDeployment) {
|
|
1554
1223
|
await import_fs3.promises.writeFile(
|
|
1555
1224
|
helm.files.watcherDeploymentYaml,
|
|
@@ -1831,7 +1500,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
|
|
|
1831
1500
|
var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
|
|
1832
1501
|
var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
|
|
1833
1502
|
var helloPeprTS = 'import {\n Capability,\n K8s,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n kind,\n} from "pepr";\nimport { MockAgent, setGlobalDispatcher } from "undici";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new action, use \'Store\' to persist data\nconst { When, Store } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Watch Action with K8s SSA (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action watches for the `pepr-demo-2` namespace to be created, then creates a ConfigMap with\n * the name `pepr-ssa-demo` and adds the namespace UID to the ConfigMap data. Because Pepr uses\n * server-side apply for this operation, the ConfigMap will be created or updated if it already exists.\n */\nWhen(a.Namespace)\n .IsCreated()\n .WithName("pepr-demo-2")\n .Watch(async ns => {\n Log.info("Namespace pepr-demo-2 was created.");\n\n try {\n // Apply the ConfigMap using K8s server-side apply\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: "pepr-ssa-demo",\n namespace: "pepr-demo-2",\n },\n data: {\n "ns-uid": ns.metadata.uid,\n },\n });\n } catch (error) {\n // You can use the Log object to log messages to the Pepr controller pod\n Log.error(error, "Failed to apply ConfigMap using server-side apply.");\n }\n\n // You can share data between actions using the Store, including between different types of actions\n Store.setItem("watch-data", "This data was stored by a Watch Action.");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.SetLabel("pepr", "was-here").SetAnnotation("pepr.dev", "annotations-work-too");\n\n // Use the Store to persist data between requests and Pepr controller pods\n Store.setItem("example-1", "was-here");\n\n // This data is written asynchronously and can be read back via `Store.getItem()` or `Store.subscribe()`\n Store.setItem("example-1-data", JSON.stringify(request.Raw.data));\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 3 different types of actions: \'Mutate\', \'Validate\', and \'Watch\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation, validate that the ConfigMap has the label\n * `pepr`, and log the request.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n })\n .Watch((cm, phase) => {\n // This Watch Action will watch the ConfigMap after it has been persisted to the cluster\n Log.info(cm, `ConfigMap was ${phase} with the name example-2`);\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap).IsCreated().InNamespace("pepr-demo-2").WithName("example-4a").Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://icanhazdadjoke.com/");\n * const joke = await fetch("https://icanhazdadjoke.com/") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://icanhazdadjoke.com")\n * ```\n */\ninterface TheChuckNorrisJoke {\n id: string;\n joke: string;\n status: number;\n}\n\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("chuck-norris")\n .Mutate(cm => cm.SetLabel("got-jokes", "true"))\n .Watch(async cm => {\n const jokeURL = "https://icanhazdadjoke.com";\n\n const mockAgent: MockAgent = new MockAgent();\n setGlobalDispatcher(mockAgent);\n const mockClient = mockAgent.get(jokeURL);\n mockClient.intercept({ path: "/", method: "GET" }).reply(\n 200,\n {\n id: "R7UfaahVfFd",\n joke: "Funny joke goes here.",\n status: 200,\n },\n {\n headers: {\n "Content-Type": "application/json; charset=utf-8",\n },\n },\n );\n\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(jokeURL, {\n headers: {\n Accept: "application/json",\n },\n });\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n const { joke } = response.data;\n // Add Joke to the Store\n await Store.setItemAndWait(jokeURL, joke);\n // Add the Chuck Norris joke to the configmap\n try {\n await K8s(kind.ConfigMap).Apply({\n metadata: {\n name: cm.metadata.name,\n namespace: cm.metadata.namespace,\n },\n data: {\n "chuck-says": Store.getItem(jokeURL),\n },\n });\n } catch (error) {\n Log.error(error, "Failed to apply ConfigMap using server-side apply.", {\n cm,\n });\n }\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * A callback function that is called once the Pepr Store is fully loaded.\n */\nStore.onReady(data => {\n Log.info(data, "Pepr Store Ready");\n});\n';
|
|
1834
|
-
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*"], version: "0.46.3-nightly.
|
|
1503
|
+
var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, files: ["/dist", "/src", "!src/**/*.test.ts", "!src/fixtures/**", "!dist/**/*.test.d.ts*"], version: "0.46.3-nightly.9", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { ci: "npm ci", "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs && npm pack", "build:image": "npm run build && docker buildx build --output type=docker --tag pepr:dev .", "build:image:unicorn": "npm run build && docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) .", "set:version": "node scripts/set-version.js", test: "npm run test:unit && npm run test:journey && npm run test:journey-wasm", "test:artifacts": "npm run build && jest src/build-artifact.test.ts", "test:integration": "npm run test:integration:prep && npm run test:integration:run", "test:integration:prep": "./integration/prep.sh", "test:integration:run": "jest --maxWorkers=4 integration", "test:journey": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run", "test:journey-wasm": "npm run test:journey:k3d && npm run build && npm run test:journey:image && npm run test:journey:run-wasm", "test:journey-wasm:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run-wasm", "test:journey:image": "docker buildx build --output type=docker --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:image:unicorn": "docker buildx build --output type=docker --tag pepr:dev $(node scripts/read-unicorn-build-args.mjs) . && k3d image import pepr:dev -c pepr-dev", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0' --wait && kubectl rollout status deployment -n kube-system", "test:journey:run": "jest --detectOpenHandles journey/entrypoint.test.ts && npm run test:journey:upgrade", "test:journey:run-wasm": "jest --detectOpenHandles journey/entrypoint-wasm.test.ts", "test:journey:unicorn": "npm run test:journey:k3d && npm run build && npm run test:journey:image:unicorn && npm run test:journey:run", "test:journey:upgrade": "npm run test:journey:k3d && npm run test:journey:image && jest --detectOpenHandles journey/pepr-upgrade.test.ts", "test:unit": "npm run gen-data-json && jest src --coverage --detectOpenHandles --coverageDirectory=./coverage --testPathIgnorePatterns='build-artifact.test.ts'", "format:check": "eslint src && prettier --config .prettierrc src --check", "format:fix": "eslint src --fix && prettier --config .prettierrc src --write", prepare: `if [ "$NODE_ENV" != 'production' ]; then husky; fi` }, dependencies: { "@types/ramda": "0.30.2", express: "4.21.2", "fast-json-patch": "3.1.1", heredoc: "^1.3.1", "http-status-codes": "^2.3.0", "json-pointer": "^0.6.2", "kubernetes-fluent-client": "3.4.5", pino: "9.6.0", "pino-pretty": "13.0.0", "prom-client": "15.1.3", ramda: "0.30.1", sigstore: "3.1.0" }, devDependencies: { "@commitlint/cli": "19.8.0", "@commitlint/config-conventional": "19.8.0", "@fast-check/jest": "^2.0.1", "@jest/globals": "29.7.0", "@types/eslint": "9.6.1", "@types/express": "5.0.1", "@types/json-pointer": "^1.0.34", "@types/node": "22.x.x", "@types/node-forge": "1.3.11", "@types/uuid": "10.0.0", "fast-check": "^4.0.0", globals: "^16.0.0", husky: "^9.1.6", jest: "29.7.0", "js-yaml": "^4.1.0", shellcheck: "^3.0.0", "ts-jest": "29.3.0", undici: "^7.0.1" }, overrides: { glob: "^9.0.0" }, peerDependencies: { "@types/prompts": "2.4.9", "@typescript-eslint/eslint-plugin": "8.23.0", "@typescript-eslint/parser": "8.23.0", commander: "13.1.0", esbuild: "0.25.0", eslint: "8.57.0", "node-forge": "1.3.1", prettier: "3.4.2", prompts: "2.4.2", typescript: "5.7.3", uuid: "11.0.5" } };
|
|
1835
1504
|
|
|
1836
1505
|
// src/cli/init/utils.ts
|
|
1837
1506
|
var import_fs4 = require("fs");
|
|
@@ -1867,7 +1536,7 @@ function write(path, data) {
|
|
|
1867
1536
|
// src/cli/init/templates.ts
|
|
1868
1537
|
var { dependencies, devDependencies, peerDependencies, scripts, version } = packageJSON;
|
|
1869
1538
|
function genPkgJSON(opts, pgkVerOverride) {
|
|
1870
|
-
const uuid = !opts.uuid ? (0, import_uuid.
|
|
1539
|
+
const uuid = !opts.uuid ? (0, import_uuid.v4)() : opts.uuid;
|
|
1871
1540
|
const name2 = sanitizeName(opts.name);
|
|
1872
1541
|
const { typescript } = peerDependencies;
|
|
1873
1542
|
const testEnv = {
|
|
@@ -1977,74 +1646,407 @@ async function formatWithPrettier(results, validateOnly) {
|
|
|
1977
1646
|
await import_fs5.promises.writeFile(filePath, formatted);
|
|
1978
1647
|
}
|
|
1979
1648
|
}
|
|
1980
|
-
return hasFailure;
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
// src/cli/format.ts
|
|
1984
|
-
function format_default(program2) {
|
|
1985
|
-
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
1986
|
-
const success = await peprFormat(opts.validateOnly);
|
|
1987
|
-
if (success) {
|
|
1988
|
-
console.info("\u2705 Module formatted");
|
|
1989
|
-
} else {
|
|
1990
|
-
process.exit(1);
|
|
1991
|
-
}
|
|
1992
|
-
});
|
|
1649
|
+
return hasFailure;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
// src/cli/format.ts
|
|
1653
|
+
function format_default(program2) {
|
|
1654
|
+
program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
|
|
1655
|
+
const success = await peprFormat(opts.validateOnly);
|
|
1656
|
+
if (success) {
|
|
1657
|
+
console.info("\u2705 Module formatted");
|
|
1658
|
+
} else {
|
|
1659
|
+
process.exit(1);
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
async function peprFormat(validateOnly) {
|
|
1664
|
+
{
|
|
1665
|
+
try {
|
|
1666
|
+
const eslint2 = new import_eslint.ESLint();
|
|
1667
|
+
const results = await eslint2.lintFiles(["./**/*.ts"]);
|
|
1668
|
+
let hasFailure = false;
|
|
1669
|
+
results.forEach(async (result) => {
|
|
1670
|
+
const errorCount = result.fatalErrorCount + result.errorCount;
|
|
1671
|
+
if (errorCount > 0) {
|
|
1672
|
+
hasFailure = true;
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
const formatter = await eslint2.loadFormatter("stylish");
|
|
1676
|
+
const resultText = await formatter.format(results, {});
|
|
1677
|
+
if (resultText) {
|
|
1678
|
+
console.log(resultText);
|
|
1679
|
+
}
|
|
1680
|
+
if (!validateOnly) {
|
|
1681
|
+
await import_eslint.ESLint.outputFixes(results);
|
|
1682
|
+
}
|
|
1683
|
+
hasFailure = await formatWithPrettier(results, validateOnly);
|
|
1684
|
+
return !hasFailure;
|
|
1685
|
+
} catch (e) {
|
|
1686
|
+
console.error(`Error formatting module:`, e);
|
|
1687
|
+
return false;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// src/lib/included-files.ts
|
|
1693
|
+
var import_fs6 = require("fs");
|
|
1694
|
+
async function createDockerfile(version3, description, includedFiles) {
|
|
1695
|
+
const file = `
|
|
1696
|
+
# Use an official Node.js runtime as the base image
|
|
1697
|
+
FROM ghcr.io/defenseunicorns/pepr/controller:v${version3}
|
|
1698
|
+
|
|
1699
|
+
LABEL description="${description}"
|
|
1700
|
+
|
|
1701
|
+
# Add the included files to the image
|
|
1702
|
+
${includedFiles.map((f) => `ADD ${f} ${f}`).join("\n")}
|
|
1703
|
+
|
|
1704
|
+
`;
|
|
1705
|
+
await import_fs6.promises.writeFile("Dockerfile.controller", file, { encoding: "utf-8" });
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// src/cli/build.helpers.ts
|
|
1709
|
+
var import_child_process2 = require("child_process");
|
|
1710
|
+
var import_esbuild = require("esbuild");
|
|
1711
|
+
var import_path2 = require("path");
|
|
1712
|
+
var import_fs8 = require("fs");
|
|
1713
|
+
|
|
1714
|
+
// src/lib/assets/yaml/generateAllYaml.ts
|
|
1715
|
+
var import_crypto2 = __toESM(require("crypto"));
|
|
1716
|
+
var import_client_node4 = require("@kubernetes/client-node");
|
|
1717
|
+
|
|
1718
|
+
// src/lib/assets/pods.ts
|
|
1719
|
+
var import_zlib = require("zlib");
|
|
1720
|
+
function getNamespace(namespaceLabels) {
|
|
1721
|
+
if (namespaceLabels) {
|
|
1722
|
+
return {
|
|
1723
|
+
apiVersion: "v1",
|
|
1724
|
+
kind: "Namespace",
|
|
1725
|
+
metadata: {
|
|
1726
|
+
name: "pepr-system",
|
|
1727
|
+
labels: namespaceLabels ?? {}
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
} else {
|
|
1731
|
+
return {
|
|
1732
|
+
apiVersion: "v1",
|
|
1733
|
+
kind: "Namespace",
|
|
1734
|
+
metadata: {
|
|
1735
|
+
name: "pepr-system"
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
function getWatcher(assets, hash, buildTimestamp, imagePullSecret) {
|
|
1741
|
+
const { name: name2, image, capabilities, config } = assets;
|
|
1742
|
+
let hasSchedule = false;
|
|
1743
|
+
const app = `${name2}-watcher`;
|
|
1744
|
+
const bindings = [];
|
|
1745
|
+
for (const capability of capabilities) {
|
|
1746
|
+
if (capability.hasSchedule) {
|
|
1747
|
+
hasSchedule = true;
|
|
1748
|
+
}
|
|
1749
|
+
const watchers = capability.bindings.filter((binding) => binding.isWatch);
|
|
1750
|
+
bindings.push(...watchers);
|
|
1751
|
+
}
|
|
1752
|
+
if (bindings.length < 1 && !hasSchedule) {
|
|
1753
|
+
return null;
|
|
1754
|
+
}
|
|
1755
|
+
const deploy = {
|
|
1756
|
+
apiVersion: "apps/v1",
|
|
1757
|
+
kind: "Deployment",
|
|
1758
|
+
metadata: {
|
|
1759
|
+
name: app,
|
|
1760
|
+
namespace: "pepr-system",
|
|
1761
|
+
annotations: {
|
|
1762
|
+
"pepr.dev/description": config.description || ""
|
|
1763
|
+
},
|
|
1764
|
+
labels: {
|
|
1765
|
+
app,
|
|
1766
|
+
"pepr.dev/controller": "watcher",
|
|
1767
|
+
"pepr.dev/uuid": config.uuid
|
|
1768
|
+
}
|
|
1769
|
+
},
|
|
1770
|
+
spec: {
|
|
1771
|
+
replicas: 1,
|
|
1772
|
+
strategy: {
|
|
1773
|
+
type: "Recreate"
|
|
1774
|
+
},
|
|
1775
|
+
selector: {
|
|
1776
|
+
matchLabels: {
|
|
1777
|
+
app,
|
|
1778
|
+
"pepr.dev/controller": "watcher"
|
|
1779
|
+
}
|
|
1780
|
+
},
|
|
1781
|
+
template: {
|
|
1782
|
+
metadata: {
|
|
1783
|
+
annotations: {
|
|
1784
|
+
buildTimestamp: `${buildTimestamp}`
|
|
1785
|
+
},
|
|
1786
|
+
labels: {
|
|
1787
|
+
app,
|
|
1788
|
+
"pepr.dev/controller": "watcher"
|
|
1789
|
+
}
|
|
1790
|
+
},
|
|
1791
|
+
spec: {
|
|
1792
|
+
terminationGracePeriodSeconds: 5,
|
|
1793
|
+
serviceAccountName: name2,
|
|
1794
|
+
securityContext: {
|
|
1795
|
+
runAsUser: 65532,
|
|
1796
|
+
runAsGroup: 65532,
|
|
1797
|
+
runAsNonRoot: true,
|
|
1798
|
+
fsGroup: 65532
|
|
1799
|
+
},
|
|
1800
|
+
containers: [
|
|
1801
|
+
{
|
|
1802
|
+
name: "watcher",
|
|
1803
|
+
image,
|
|
1804
|
+
imagePullPolicy: "IfNotPresent",
|
|
1805
|
+
args: ["/app/node_modules/pepr/dist/controller.js", hash],
|
|
1806
|
+
readinessProbe: {
|
|
1807
|
+
httpGet: {
|
|
1808
|
+
path: "/healthz",
|
|
1809
|
+
port: 3e3,
|
|
1810
|
+
scheme: "HTTPS"
|
|
1811
|
+
},
|
|
1812
|
+
initialDelaySeconds: 10
|
|
1813
|
+
},
|
|
1814
|
+
livenessProbe: {
|
|
1815
|
+
httpGet: {
|
|
1816
|
+
path: "/healthz",
|
|
1817
|
+
port: 3e3,
|
|
1818
|
+
scheme: "HTTPS"
|
|
1819
|
+
},
|
|
1820
|
+
initialDelaySeconds: 10
|
|
1821
|
+
},
|
|
1822
|
+
ports: [
|
|
1823
|
+
{
|
|
1824
|
+
containerPort: 3e3
|
|
1825
|
+
}
|
|
1826
|
+
],
|
|
1827
|
+
resources: {
|
|
1828
|
+
requests: {
|
|
1829
|
+
memory: "256Mi",
|
|
1830
|
+
cpu: "200m"
|
|
1831
|
+
},
|
|
1832
|
+
limits: {
|
|
1833
|
+
memory: "512Mi",
|
|
1834
|
+
cpu: "500m"
|
|
1835
|
+
}
|
|
1836
|
+
},
|
|
1837
|
+
securityContext: {
|
|
1838
|
+
runAsUser: 65532,
|
|
1839
|
+
runAsGroup: 65532,
|
|
1840
|
+
runAsNonRoot: true,
|
|
1841
|
+
allowPrivilegeEscalation: false,
|
|
1842
|
+
capabilities: {
|
|
1843
|
+
drop: ["ALL"]
|
|
1844
|
+
}
|
|
1845
|
+
},
|
|
1846
|
+
volumeMounts: [
|
|
1847
|
+
{
|
|
1848
|
+
name: "tls-certs",
|
|
1849
|
+
mountPath: "/etc/certs",
|
|
1850
|
+
readOnly: true
|
|
1851
|
+
},
|
|
1852
|
+
{
|
|
1853
|
+
name: "module",
|
|
1854
|
+
mountPath: `/app/load`,
|
|
1855
|
+
readOnly: true
|
|
1856
|
+
}
|
|
1857
|
+
],
|
|
1858
|
+
env: genEnv(config, true)
|
|
1859
|
+
}
|
|
1860
|
+
],
|
|
1861
|
+
volumes: [
|
|
1862
|
+
{
|
|
1863
|
+
name: "tls-certs",
|
|
1864
|
+
secret: {
|
|
1865
|
+
secretName: `${name2}-tls`
|
|
1866
|
+
}
|
|
1867
|
+
},
|
|
1868
|
+
{
|
|
1869
|
+
name: "module",
|
|
1870
|
+
secret: {
|
|
1871
|
+
secretName: `${name2}-module`
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
]
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
if (imagePullSecret) {
|
|
1880
|
+
deploy.spec.template.spec.imagePullSecrets = [{ name: imagePullSecret }];
|
|
1881
|
+
}
|
|
1882
|
+
return deploy;
|
|
1993
1883
|
}
|
|
1994
|
-
|
|
1995
|
-
{
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
1884
|
+
function getDeployment(assets, hash, buildTimestamp, imagePullSecret) {
|
|
1885
|
+
const { name: name2, image, config } = assets;
|
|
1886
|
+
const app = name2;
|
|
1887
|
+
const deploy = {
|
|
1888
|
+
apiVersion: "apps/v1",
|
|
1889
|
+
kind: "Deployment",
|
|
1890
|
+
metadata: {
|
|
1891
|
+
name: name2,
|
|
1892
|
+
namespace: "pepr-system",
|
|
1893
|
+
annotations: {
|
|
1894
|
+
"pepr.dev/description": config.description || ""
|
|
1895
|
+
},
|
|
1896
|
+
labels: {
|
|
1897
|
+
app,
|
|
1898
|
+
"pepr.dev/controller": "admission",
|
|
1899
|
+
"pepr.dev/uuid": config.uuid
|
|
2010
1900
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
1901
|
+
},
|
|
1902
|
+
spec: {
|
|
1903
|
+
replicas: 2,
|
|
1904
|
+
selector: {
|
|
1905
|
+
matchLabels: {
|
|
1906
|
+
app,
|
|
1907
|
+
"pepr.dev/controller": "admission"
|
|
1908
|
+
}
|
|
1909
|
+
},
|
|
1910
|
+
template: {
|
|
1911
|
+
metadata: {
|
|
1912
|
+
annotations: {
|
|
1913
|
+
buildTimestamp: `${buildTimestamp}`
|
|
1914
|
+
},
|
|
1915
|
+
labels: {
|
|
1916
|
+
app,
|
|
1917
|
+
"pepr.dev/controller": "admission"
|
|
1918
|
+
}
|
|
1919
|
+
},
|
|
1920
|
+
spec: {
|
|
1921
|
+
terminationGracePeriodSeconds: 5,
|
|
1922
|
+
priorityClassName: "system-node-critical",
|
|
1923
|
+
serviceAccountName: name2,
|
|
1924
|
+
securityContext: {
|
|
1925
|
+
runAsUser: 65532,
|
|
1926
|
+
runAsGroup: 65532,
|
|
1927
|
+
runAsNonRoot: true,
|
|
1928
|
+
fsGroup: 65532
|
|
1929
|
+
},
|
|
1930
|
+
containers: [
|
|
1931
|
+
{
|
|
1932
|
+
name: "server",
|
|
1933
|
+
image,
|
|
1934
|
+
imagePullPolicy: "IfNotPresent",
|
|
1935
|
+
args: ["/app/node_modules/pepr/dist/controller.js", hash],
|
|
1936
|
+
readinessProbe: {
|
|
1937
|
+
httpGet: {
|
|
1938
|
+
path: "/healthz",
|
|
1939
|
+
port: 3e3,
|
|
1940
|
+
scheme: "HTTPS"
|
|
1941
|
+
},
|
|
1942
|
+
initialDelaySeconds: 10
|
|
1943
|
+
},
|
|
1944
|
+
livenessProbe: {
|
|
1945
|
+
httpGet: {
|
|
1946
|
+
path: "/healthz",
|
|
1947
|
+
port: 3e3,
|
|
1948
|
+
scheme: "HTTPS"
|
|
1949
|
+
},
|
|
1950
|
+
initialDelaySeconds: 10
|
|
1951
|
+
},
|
|
1952
|
+
ports: [
|
|
1953
|
+
{
|
|
1954
|
+
containerPort: 3e3
|
|
1955
|
+
}
|
|
1956
|
+
],
|
|
1957
|
+
resources: {
|
|
1958
|
+
requests: {
|
|
1959
|
+
memory: "256Mi",
|
|
1960
|
+
cpu: "200m"
|
|
1961
|
+
},
|
|
1962
|
+
limits: {
|
|
1963
|
+
memory: "512Mi",
|
|
1964
|
+
cpu: "500m"
|
|
1965
|
+
}
|
|
1966
|
+
},
|
|
1967
|
+
env: genEnv(config),
|
|
1968
|
+
securityContext: {
|
|
1969
|
+
runAsUser: 65532,
|
|
1970
|
+
runAsGroup: 65532,
|
|
1971
|
+
runAsNonRoot: true,
|
|
1972
|
+
allowPrivilegeEscalation: false,
|
|
1973
|
+
capabilities: {
|
|
1974
|
+
drop: ["ALL"]
|
|
1975
|
+
}
|
|
1976
|
+
},
|
|
1977
|
+
volumeMounts: [
|
|
1978
|
+
{
|
|
1979
|
+
name: "tls-certs",
|
|
1980
|
+
mountPath: "/etc/certs",
|
|
1981
|
+
readOnly: true
|
|
1982
|
+
},
|
|
1983
|
+
{
|
|
1984
|
+
name: "api-path",
|
|
1985
|
+
mountPath: "/app/api-path",
|
|
1986
|
+
readOnly: true
|
|
1987
|
+
},
|
|
1988
|
+
{
|
|
1989
|
+
name: "module",
|
|
1990
|
+
mountPath: `/app/load`,
|
|
1991
|
+
readOnly: true
|
|
1992
|
+
}
|
|
1993
|
+
]
|
|
1994
|
+
}
|
|
1995
|
+
],
|
|
1996
|
+
volumes: [
|
|
1997
|
+
{
|
|
1998
|
+
name: "tls-certs",
|
|
1999
|
+
secret: {
|
|
2000
|
+
secretName: `${name2}-tls`
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
{
|
|
2004
|
+
name: "api-path",
|
|
2005
|
+
secret: {
|
|
2006
|
+
secretName: `${name2}-api-path`
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
{
|
|
2010
|
+
name: "module",
|
|
2011
|
+
secret: {
|
|
2012
|
+
secretName: `${name2}-module`
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
]
|
|
2016
|
+
}
|
|
2013
2017
|
}
|
|
2014
|
-
hasFailure = await formatWithPrettier(results, validateOnly);
|
|
2015
|
-
return !hasFailure;
|
|
2016
|
-
} catch (e) {
|
|
2017
|
-
console.error(`Error formatting module:`, e);
|
|
2018
|
-
return false;
|
|
2019
2018
|
}
|
|
2019
|
+
};
|
|
2020
|
+
if (imagePullSecret) {
|
|
2021
|
+
deploy.spec.template.spec.imagePullSecrets = [{ name: imagePullSecret }];
|
|
2020
2022
|
}
|
|
2023
|
+
return deploy;
|
|
2021
2024
|
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2025
|
+
function getModuleSecret(name2, data, hash) {
|
|
2026
|
+
const compressed = (0, import_zlib.gzipSync)(data);
|
|
2027
|
+
const path = `module-${hash}.js.gz`;
|
|
2028
|
+
const compressedData = compressed.toString("base64");
|
|
2029
|
+
if (secretOverLimit(compressedData)) {
|
|
2030
|
+
const error = new Error(`Module secret for ${name2} is over the 1MB limit`);
|
|
2031
|
+
console.error("Uncaught Exception:", error);
|
|
2032
|
+
process.exit(1);
|
|
2033
|
+
} else {
|
|
2034
|
+
return {
|
|
2035
|
+
apiVersion: "v1",
|
|
2036
|
+
kind: "Secret",
|
|
2037
|
+
metadata: {
|
|
2038
|
+
name: `${name2}-module`,
|
|
2039
|
+
namespace: "pepr-system"
|
|
2040
|
+
},
|
|
2041
|
+
type: "Opaque",
|
|
2042
|
+
data: {
|
|
2043
|
+
[path]: compressed.toString("base64")
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
}
|
|
2037
2047
|
}
|
|
2038
2048
|
|
|
2039
|
-
// src/cli/build.helpers.ts
|
|
2040
|
-
var import_child_process2 = require("child_process");
|
|
2041
|
-
var import_esbuild = require("esbuild");
|
|
2042
|
-
var import_path2 = require("path");
|
|
2043
|
-
var import_fs8 = require("fs");
|
|
2044
|
-
|
|
2045
2049
|
// src/lib/assets/yaml/generateAllYaml.ts
|
|
2046
|
-
var import_crypto2 = __toESM(require("crypto"));
|
|
2047
|
-
var import_client_node4 = require("@kubernetes/client-node");
|
|
2048
2050
|
var import_fs7 = require("fs");
|
|
2049
2051
|
|
|
2050
2052
|
// src/lib/assets/webhooks.ts
|
|
@@ -2286,7 +2288,7 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
2286
2288
|
const yamlFile = `pepr-module-${uuid}.yaml`;
|
|
2287
2289
|
const chartPath = `${uuid}-chart`;
|
|
2288
2290
|
const yamlPath = (0, import_path2.resolve)(outputDir2, yamlFile);
|
|
2289
|
-
const yaml = await assets.allYaml(generateAllYaml, imagePullSecret);
|
|
2291
|
+
const yaml = await assets.allYaml(generateAllYaml, getDeployment, getWatcher, imagePullSecret);
|
|
2290
2292
|
const zarfPath = (0, import_path2.resolve)(outputDir2, "zarf.yaml");
|
|
2291
2293
|
let localZarf = "";
|
|
2292
2294
|
if (zarf === "chart") {
|
|
@@ -2296,7 +2298,7 @@ async function generateYamlAndWriteToDisk(obj) {
|
|
|
2296
2298
|
}
|
|
2297
2299
|
await import_fs8.promises.writeFile(yamlPath, yaml);
|
|
2298
2300
|
await import_fs8.promises.writeFile(zarfPath, localZarf);
|
|
2299
|
-
await assets.generateHelmChart(webhookConfigGenerator, outputDir2);
|
|
2301
|
+
await assets.generateHelmChart(webhookConfigGenerator, getWatcher, getModuleSecret, outputDir2);
|
|
2300
2302
|
console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
|
|
2301
2303
|
}
|
|
2302
2304
|
|