Skip to content

Commit

Permalink
Adding more printer columns to the CRD, setting status.display.state
Browse files Browse the repository at this point in the history
  • Loading branch information
prachidamle committed Sep 4, 2020
1 parent 3c1c237 commit b02411a
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 16 deletions.
50 changes: 50 additions & 0 deletions crds/clusterscan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ kind: CustomResourceDefinition
metadata:
name: clusterscans.cis.cattle.io
spec:
additionalPrinterColumns:
- JSONPath: .status.display.state
name: Status
type: string
- JSONPath: .status.lastRunScanProfileName
name: ClusterScanProfile
type: string
- JSONPath: .status.summary.total
name: Total
type: string
- JSONPath: .status.summary.pass
name: Pass
type: string
- JSONPath: .status.summary.fail
name: Fail
type: string
- JSONPath: .status.summary.skip
name: Skip
type: string
- JSONPath: .status.summary.notApplicable
name: Not Applicable
type: string
- JSONPath: .status.lastRunTimestamp
name: LastRunTimestamp
type: string
group: cis.cattle.io
names:
kind: ClusterScan
Expand All @@ -16,6 +41,7 @@ spec:
spec:
properties:
scanProfileName:
nullable: true
type: string
type: object
status:
Expand All @@ -24,21 +50,45 @@ spec:
items:
properties:
lastTransitionTime:
nullable: true
type: string
lastUpdateTime:
nullable: true
type: string
message:
nullable: true
type: string
reason:
nullable: true
type: string
status:
nullable: true
type: string
type:
nullable: true
type: string
type: object
nullable: true
type: array
display:
nullable: true
properties:
error:
type: boolean
message:
nullable: true
type: string
state:
nullable: true
type: string
transitioning:
type: boolean
type: object
lastRunScanProfileName:
nullable: true
type: string
lastRunTimestamp:
nullable: true
type: string
observedGeneration:
type: integer
Expand Down
15 changes: 15 additions & 0 deletions crds/clusterscanbenchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ kind: CustomResourceDefinition
metadata:
name: clusterscanbenchmarks.cis.cattle.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.clusterProvider
name: ClusterProvider
type: string
- JSONPath: .spec.minKubernetesVersion
name: MinKubernetesVersion
type: string
- JSONPath: .spec.maxKubernetesVersion
name: MaxKubernetesVersion
type: string
group: cis.cattle.io
names:
kind: ClusterScanBenchmark
Expand All @@ -16,14 +26,19 @@ spec:
spec:
properties:
clusterProvider:
nullable: true
type: string
customBenchmarkConfigMapName:
nullable: true
type: string
customBenchmarkConfigMapNameSpace:
nullable: true
type: string
maxKubernetesVersion:
nullable: true
type: string
minKubernetesVersion:
nullable: true
type: string
type: object
type: object
Expand Down
6 changes: 6 additions & 0 deletions crds/clusterscanprofile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ kind: CustomResourceDefinition
metadata:
name: clusterscanprofiles.cis.cattle.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.benchmarkVersion
name: BenchmarkVersion
type: string
group: cis.cattle.io
names:
kind: ClusterScanProfile
Expand All @@ -16,9 +20,11 @@ spec:
spec:
properties:
benchmarkVersion:
nullable: true
type: string
skipTests:
items:
nullable: true
type: string
nullable: true
type: array
Expand Down
10 changes: 10 additions & 0 deletions crds/clusterscanreport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ kind: CustomResourceDefinition
metadata:
name: clusterscanreports.cis.cattle.io
spec:
additionalPrinterColumns:
- JSONPath: .spec.lastRunTimestamp
name: LastRunTimestamp
type: string
- JSONPath: .spec.benchmarkVersion
name: BenchmarkVersion
type: string
group: cis.cattle.io
names:
kind: ClusterScanReport
Expand All @@ -16,10 +23,13 @@ spec:
spec:
properties:
benchmarkVersion:
nullable: true
type: string
lastRunTimestamp:
nullable: true
type: string
reportJSON:
nullable: true
type: string
type: object
type: object
Expand Down
17 changes: 13 additions & 4 deletions pkg/apis/cis.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ type ClusterScanSpec struct {
}

type ClusterScanStatus struct {
LastRunTimestamp string `yaml:"last_run_timestamp" json:"lastRunTimestamp"`
Summary *ClusterScanSummary `json:"summary,omitempty"`
ObservedGeneration int64 `json:"observedGeneration"`
Conditions []genericcondition.GenericCondition `json:"conditions,omitempty"`
Display *ClusterScanStatusDisplay `json:"display,omitempty"`
LastRunTimestamp string `yaml:"last_run_timestamp" json:"lastRunTimestamp"`
LastRunScanProfileName string `json:"lastRunScanProfileName,omitempty"`
Summary *ClusterScanSummary `json:"summary,omitempty"`
ObservedGeneration int64 `json:"observedGeneration"`
Conditions []genericcondition.GenericCondition `json:"conditions,omitempty"`
}

type ClusterScanStatusDisplay struct {
State string `json:"state"`
Message string `json:"message"`
Error bool `json:"error"`
Transitioning bool `json:"transitioning"`
}

type ClusterScanSummary struct {
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/cis.cattle.io/v1/zz_generated_deepcopy.go

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

25 changes: 18 additions & 7 deletions pkg/crds/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,30 @@ func WriteCRD() error {
func List() []crd.CRD {
return []crd.CRD{
newCRD(&cisoperator.ClusterScan{}, func(c crd.CRD) crd.CRD {
return c
return c.
WithColumn("Status", ".status.display.state").
WithColumn("ClusterScanProfile", ".status.lastRunScanProfileName").
WithColumn("Total", ".status.summary.total").
WithColumn("Pass", ".status.summary.pass").
WithColumn("Fail", ".status.summary.fail").
WithColumn("Skip", ".status.summary.skip").
WithColumn("Not Applicable", ".status.summary.notApplicable").
WithColumn("LastRunTimestamp", ".status.lastRunTimestamp")
}),
newCRD(&cisoperator.ClusterScanProfile{}, func(c crd.CRD) crd.CRD {
return c
return c.
WithColumn("BenchmarkVersion", ".spec.benchmarkVersion")
}),
newCRD(&cisoperator.ClusterScanReport{}, func(c crd.CRD) crd.CRD {
return c
}),
newCRD(&cisoperator.ScheduledScan{}, func(c crd.CRD) crd.CRD {
return c
return c.
WithColumn("LastRunTimestamp", ".spec.lastRunTimestamp").
WithColumn("BenchmarkVersion", ".spec.benchmarkVersion")
}),
newCRD(&cisoperator.ClusterScanBenchmark{}, func(c crd.CRD) crd.CRD {
return c
return c.
WithColumn("ClusterProvider", ".spec.clusterProvider").
WithColumn("MinKubernetesVersion", ".spec.minKubernetesVersion").
WithColumn("MaxKubernetesVersion", ".spec.maxKubernetesVersion")
}),
}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/generated/controllers/cis.cattle.io/v1/clusterscan.go

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

5 changes: 5 additions & 0 deletions pkg/generated/controllers/cis.cattle.io/v1/scheduledscan.go

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

4 changes: 3 additions & 1 deletion pkg/securityscan/jobHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func (c *Controller) handleJobs(ctx context.Context) error {
v1.ClusterScanConditionAlerted.Unknown(scan)
scan.Status.ObservedGeneration = scan.Generation
logrus.Infof("Marking ClusterScanConditionAlerted for scan: %v", scanName)
c.setClusterScanStatusDisplay(scan)

//update scan
_, err = scans.UpdateStatus(scan)
if err != nil {
Expand All @@ -80,7 +82,7 @@ func (c *Controller) handleJobs(ctx context.Context) error {
return nil, fmt.Errorf("error %v reading results of cluster scan object: %v", err, scanName)
}
scancopy.Status.Summary = summary
err = c.apply.WithCacheTypes(reports).ApplyObjects(report)
err = c.apply.WithSetID(report.Name).WithCacheTypes(reports).ApplyObjects(report)
if err != nil {
return nil, fmt.Errorf("error %v saving clusterscanreport object", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/securityscan/podHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (c *Controller) handlePods(ctx context.Context) error {
}
logrus.Infof("Marking ClusterScanConditionFailed for scan: %v, error %v", scanName, done)
}
c.setClusterScanStatusDisplay(scanCopy)
//update scan
_, err = scans.UpdateStatus(scanCopy)
if err != nil {
Expand Down
Loading

0 comments on commit b02411a

Please sign in to comment.