Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit fe2bd39

Browse files
committed
Added generated target code
1 parent b133f73 commit fe2bd39

File tree

12 files changed

+300
-0
lines changed

12 files changed

+300
-0
lines changed

operator/PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ resources:
1313
- group: scans
1414
kind: PersistenceProvider
1515
version: v1
16+
- group: scans
17+
kind: Target
18+
version: v1
1619
version: "2"

operator/api/v1/target_types.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// TargetSpec defines the desired state of Target
27+
type TargetSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of Target. Edit Target_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// TargetStatus defines the observed state of Target
36+
type TargetStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
// +kubebuilder:object:root=true
42+
43+
// Target is the Schema for the targets API
44+
type Target struct {
45+
metav1.TypeMeta `json:",inline"`
46+
metav1.ObjectMeta `json:"metadata,omitempty"`
47+
48+
Spec TargetSpec `json:"spec,omitempty"`
49+
Status TargetStatus `json:"status,omitempty"`
50+
}
51+
52+
// +kubebuilder:object:root=true
53+
54+
// TargetList contains a list of Target
55+
type TargetList struct {
56+
metav1.TypeMeta `json:",inline"`
57+
metav1.ListMeta `json:"metadata,omitempty"`
58+
Items []Target `json:"items"`
59+
}
60+
61+
func init() {
62+
SchemeBuilder.Register(&Target{}, &TargetList{})
63+
}

operator/api/v1/zz_generated.deepcopy.go

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/config/crd/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ resources:
66
- bases/scans.experimental.securecodebox.io_scantemplates.yaml
77
- bases/scans.experimental.securecodebox.io_parsedefinitions.yaml
88
- bases/scans.experimental.securecodebox.io_persistenceproviders.yaml
9+
- bases/scans.experimental.securecodebox.io_targets.yaml
910
# +kubebuilder:scaffold:crdkustomizeresource
1011

1112
patchesStrategicMerge:
@@ -15,6 +16,7 @@ patchesStrategicMerge:
1516
#- patches/webhook_in_scantemplates.yaml
1617
#- patches/webhook_in_parsedefinitions.yaml
1718
#- patches/webhook_in_persistenceproviders.yaml
19+
#- patches/webhook_in_targets.yaml
1820
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1921

2022
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
@@ -23,6 +25,7 @@ patchesStrategicMerge:
2325
#- patches/cainjection_in_scantemplates.yaml
2426
#- patches/cainjection_in_parsedefinitions.yaml
2527
#- patches/cainjection_in_persistenceproviders.yaml
28+
#- patches/cainjection_in_targets.yaml
2629
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
2730

2831
# the following config is for teaching kustomize how to do kustomization for CRDs.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: targets.scans.experimental.securecodebox.io
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: targets.scans.experimental.securecodebox.io
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13+
caBundle: Cg==
14+
service:
15+
namespace: system
16+
name: webhook-service
17+
path: /convert
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# permissions to do edit targets.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: target-editor-role
6+
rules:
7+
- apiGroups:
8+
- scans.experimental.securecodebox.io
9+
resources:
10+
- targets
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- scans.experimental.securecodebox.io
21+
resources:
22+
- targets/status
23+
verbs:
24+
- get
25+
- patch
26+
- update
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# permissions to do viewer targets.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: target-viewer-role
6+
rules:
7+
- apiGroups:
8+
- scans.experimental.securecodebox.io
9+
resources:
10+
- targets
11+
verbs:
12+
- get
13+
- list
14+
- watch
15+
- apiGroups:
16+
- scans.experimental.securecodebox.io
17+
resources:
18+
- targets/status
19+
verbs:
20+
- get
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: scans.experimental.securecodebox.io/v1
2+
kind: Target
3+
metadata:
4+
name: target-sample
5+
spec:
6+
# Add fields here
7+
foo: bar

operator/controllers/suite_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ var _ = BeforeSuite(func(done Done) {
6565
err = scansv1.AddToScheme(scheme.Scheme)
6666
Expect(err).NotTo(HaveOccurred())
6767

68+
err = scansv1.AddToScheme(scheme.Scheme)
69+
Expect(err).NotTo(HaveOccurred())
70+
6871
// +kubebuilder:scaffold:scheme
6972

7073
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})

0 commit comments

Comments
 (0)