Skip to content

Commit

Permalink
Add existing API (giantswarm#6)
Browse files Browse the repository at this point in the history
* Add existing API

* Ignore deadcode check in generated test

* Silence unused in test

* Remove default suite_test

* Go mod

* Import and reconcile VulnerabilityReport

* Nancy

* Add helm packaging

* cleanups

* Actually push the image

* Require pushing before adding to catalog

* Fix project name

* Don't copy nonexistent /api folder in Dockerfile

* Register scheme

* Sort imports

* Check registration return value

* Allow get,list for vulnerbailityreports

* Also watch
  • Loading branch information
stone-z authored Nov 16, 2021
1 parent 9c187e5 commit 8361c40
Show file tree
Hide file tree
Showing 19 changed files with 951 additions and 36 deletions.
76 changes: 71 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,80 @@
version: 2.1

orbs:
architect: giantswarm/[email protected]

workflows:
test:
package-and-push-chart-on-tag:
jobs:
- architect/go-test:
name: go-test
- architect/go-build:
name: go-build
binary: starboard-exporter
filters:
tags:
only: /^v.*/

- architect/push-to-docker:
context: "architect"
name: push-starboard-exporter-to-docker
image: "docker.io/giantswarm/starboard-exporter"
username_envar: "DOCKER_USERNAME"
password_envar: "DOCKER_PASSWORD"
requires:
- go-build
# Needed to trigger job also on git tag.
filters:
tags:
only: /^v.*/

- architect/push-to-docker:
context: "architect"
name: push-starboard-exporter-to-quay
image: "quay.io/giantswarm/starboard-exporter"
username_envar: "QUAY_USERNAME"
password_envar: "QUAY_PASSWORD"
requires:
- go-build
# Needed to trigger job also on git tag.
filters:
tags:
only: /^v.*/

- architect/push-to-docker:
context: "architect"
name: push-starboard-exporter-to-aliyun
image: "registry-intl.cn-shanghai.aliyuncs.com/giantswarm/starboard-exporter"
username_envar: "ALIYUN_USERNAME"
password_envar: "ALIYUN_PASSWORD"
requires:
- go-build
# Needed to trigger job also on git tag.
filters:
tags:
only: /^v.*/

- architect/push-to-app-catalog:
context: "architect"
name: push-starboard-exporter-to-control-plane-catalog
app_catalog: "control-plane-catalog"
app_catalog_test: "control-plane-test-catalog"
chart: "starboard-exporter"
requires:
- push-starboard-exporter-to-docker
- push-starboard-exporter-to-quay
# Trigger job on git tag.
filters:
tags:
only: /^v.*/

- architect/push-to-app-catalog:
context: "architect"
name: push-starboard-exporter-to-giantswarm-catalog
app_catalog: "giantswarm-catalog"
app_catalog_test: "giantswarm-test-catalog"
chart: "starboard-exporter"
requires:
- push-starboard-exporter-to-docker
- push-starboard-exporter-to-quay
# Trigger job on git tag.
filters:
# Trigger job also on git tag.
tags:
only: /^v.*/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ testbin/*
*.swp
*.swo
*~

# project binary
/starboard-exporter
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
# COPY api/ api/
COPY controllers/ controllers/

# Build
Expand Down
6 changes: 6 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ layout:
- go.kubebuilder.io/v3
projectName: starboard-exporter
repo: github.com/giantswarm/starboard-exporter
resources:
- controller: true
domain: giantswarm
group: aquasecurity.github.io
kind: VulnerabilityReport
version: v1alpha1
version: "3"
63 changes: 63 additions & 0 deletions controllers/vulnerabilityreport_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

aqua "github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
)

// VulnerabilityReportReconciler reconciles a VulnerabilityReport object
type VulnerabilityReportReconciler struct {
client.Client
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=aquasecurity.github.io.giantswarm,resources=vulnerabilityreports,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=aquasecurity.github.io.giantswarm,resources=vulnerabilityreports/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=aquasecurity.github.io.giantswarm,resources=vulnerabilityreports/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the VulnerabilityReport object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
func (r *VulnerabilityReportReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

// TODO(user): your logic here

return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *VulnerabilityReportReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
// Uncomment the following line adding a pointer to an instance of the controlled resource as an argument
For(&aqua.VulnerabilityReport{}).
Complete(r)
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/giantswarm/starboard-exporter
go 1.16

require (
k8s.io/apimachinery v0.22.1
k8s.io/client-go v0.22.1
sigs.k8s.io/controller-runtime v0.10.0
github.com/aquasecurity/starboard v0.13.0
k8s.io/apimachinery v0.22.3
k8s.io/client-go v0.22.3
sigs.k8s.io/controller-runtime v0.10.3
)

replace (
github.com/containerd/containerd => github.com/containerd/containerd v1.5.7
github.com/coreos/etcd => github.com/coreos/etcd v3.3.27+incompatible
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt v3.2.2+incompatible
)
Loading

0 comments on commit 8361c40

Please sign in to comment.