Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: v1 api #544

Merged
merged 12 commits into from
Jan 6, 2023
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ manifests: __controller-gen ## Generates k8s yaml for eraser deployment.
k8s.gcr.io/kustomize/kustomize:v${KUSTOMIZE_VERSION} build \
--load_restrictor LoadRestrictionsNone /eraser/third_party/open-policy-agent/gatekeeper/helmify | go run third_party/open-policy-agent/gatekeeper/helmify/*.go

generate: __controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
# Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method
# implementations. Also generate conversions between structs of different API versions.
generate: __conversion-gen __controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CONVERSION_GEN) \
--output-base=/eraser \
--input-dirs=./api/... \
--go-header-file=./hack/boilerplate.go.txt \
--output-file-base=zz_generated.conversion

fmt: ## Run go fmt against code.
go fmt ./...
Expand Down Expand Up @@ -239,6 +246,9 @@ bin/setup-envtest:
__controller-gen: __tooling-image
CONTROLLER_GEN=docker run --rm -v $(shell pwd):/eraser eraser-tooling controller-gen

__conversion-gen: __tooling-image
CONVERSION_GEN=docker run --rm -v $(shell pwd):/eraser eraser-tooling conversion-gen

__tooling-image:
docker build . \
-t eraser-tooling \
Expand Down
4 changes: 4 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ resources:
group: eraser.sh
kind: ImageCollector
version: v1alpha1
- domain: azure-eraser.io
group: eraser.sh
kind: ImageList
version: v1
version: "3"
16 changes: 16 additions & 0 deletions api/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
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 apis
3 changes: 3 additions & 0 deletions api/unversioned/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package unversioned

// +kubebuilder:object:generate=true
76 changes: 76 additions & 0 deletions api/unversioned/imagejob_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
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.
*/

// +kubebuilder:skip
package unversioned

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type Image struct {
ImageID string `json:"image_id"`
Names []string `json:"names,omitempty"`
Digests []string `json:"digests,omitempty"`
}

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// JobPhase defines the phase of an ImageJob status.
type JobPhase string

const (
PhaseRunning JobPhase = "Running"
PhaseCompleted JobPhase = "Completed"
PhaseFailed JobPhase = "Failed"
)

// ImageJobStatus defines the observed state of ImageJob.
type ImageJobStatus struct {
// number of pods that failed
Failed int `json:"failed"`

// number of pods that completed successfully
Succeeded int `json:"succeeded"`

// desired number of pods
Desired int `json:"desired"`

// number of nodes that were skipped e.g. because they are not a linux node
Skipped int `json:"skipped"`

// job running, successfully completed, or failed
Phase JobPhase `json:"phase"`

// Time to delay deletion until
DeleteAfter *metav1.Time `json:"deleteAfter,omitempty"`
}

// ImageJob is the Schema for the imagejobs API.
type ImageJob struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status ImageJobStatus `json:"status,omitempty"`
}

// ImageJobList contains a list of ImageJob.
type ImageJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ImageJob `json:"items"`
}
53 changes: 53 additions & 0 deletions api/unversioned/imagelist_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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.
*/

// +kubebuilder:skip
package unversioned

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ImageListSpec defines the desired state of ImageList.
type ImageListSpec struct {
// The list of non-compliant images to delete if non-running.
Images []string `json:"images"`
}

// ImageListStatus defines the observed state of ImageList.
type ImageListStatus struct {
// Information when the job was completed.
Timestamp *metav1.Time `json:"timestamp"`
// Number of nodes that successfully ran the job
Success int64 `json:"success"`
// Number of nodes that failed to run the job
Failed int64 `json:"failed"`
// Number of nodes that were skipped due to a skip selector
Skipped int64 `json:"skipped"`
}

// ImageList is the Schema for the imagelists API.
type ImageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ImageListSpec `json:"spec,omitempty"`
Status ImageListStatus `json:"status,omitempty"`
}

// ImageListList contains a list of ImageList.
type ImageListList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ImageList `json:"items"`
}
192 changes: 192 additions & 0 deletions api/unversioned/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions api/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// +k8s:conversion-gen=github.com/Azure/eraser/api/unversioned
package v1
Loading