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

Update API versions to v1 #78

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions PROJECT

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Inspect the sample configurations below and update the PROJECT_ID as appropriate

```yaml
# googlecasissuer-sample.yaml
apiVersion: cas-issuer.jetstack.io/v1beta1
apiVersion: cas-issuer.jetstack.io/v1
kind: GoogleCASIssuer
metadata:
name: googlecasissuer-sample
Expand All @@ -212,7 +212,7 @@ or

```yaml
# googlecasclusterissuer-sample.yaml
apiVersion: cas-issuer.jetstack.io/v1beta1
apiVersion: cas-issuer.jetstack.io/v1
kind: GoogleCASClusterIssuer
metadata:
name: googlecasclusterissuer-sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package v1

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

// 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.

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:printcolumn:name="ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1
package v1

import (
cmmetav1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// 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.

// GoogleCASIssuerSpec defines the desired state of GoogleCASIssuer
type GoogleCASIssuerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Project is the Google Cloud Project ID
Project string `json:"project,omitempty"`

Expand All @@ -51,9 +45,6 @@ type GoogleCASIssuerSpec struct {

// GoogleCASIssuerStatus defines the observed state of GoogleCASIssuer
type GoogleCASIssuerStatus struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +optional
Conditions []GoogleCASIssuerCondition `json:"conditions,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1beta1 contains API Schema definitions for the issuers v1beta1 API group
// Package v1 contains API Schema definitions for the issuers v1 API group
// +kubebuilder:object:generate=true
// +groupName=cas-issuer.jetstack.io
package v1beta1
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "cas-issuer.jetstack.io", Version: "v1beta1"}
GroupVersion = schema.GroupVersion{Group: "cas-issuer.jetstack.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down

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

4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"

issuersv1beta1 "github.com/jetstack/google-cas-issuer/api/v1beta1"
issuersv1 "github.com/jetstack/google-cas-issuer/api/v1"
"github.com/jetstack/google-cas-issuer/pkg/controller/certificaterequest"
"github.com/jetstack/google-cas-issuer/pkg/controller/issuer"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func root() error {
setupLog.Error(err, "couldn't add cert-manager scheme")
return err
}
if err := issuersv1beta1.AddToScheme(scheme); err != nil {
if err := issuersv1.AddToScheme(scheme); err != nil {
setupLog.Error(err, "couldn't add cert-manager scheme")
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- jsonPath: .status.conditions[?(@.type=='Ready')].message
name: message
type: string
name: v1beta1
name: v1
schema:
openAPIV3Schema:
description: GoogleCASClusterIssuer is the Schema for the googlecasclusterissuers API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- jsonPath: .status.conditions[?(@.type=='Ready')].message
name: message
type: string
name: v1beta1
name: v1
schema:
openAPIV3Schema:
description: GoogleCASIssuer is the Schema for the googlecasissuers API
Expand Down
8 changes: 4 additions & 4 deletions pkg/cas/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/jetstack/google-cas-issuer/api/v1beta1"
"github.com/jetstack/google-cas-issuer/api/v1"
)

// A Signer is an abstraction of a certificate authority
Expand All @@ -48,7 +48,7 @@ type casSigner struct {
// parent is the Google cloud project ID in the format "projects/*/locations/*"
parent string
// spec is a reference to the issuer Spec
spec *v1beta1.GoogleCASIssuerSpec
spec *v1.GoogleCASIssuerSpec
// namespace is the namespace to look for secrets in
namespace string

Expand Down Expand Up @@ -85,7 +85,7 @@ func (c *casSigner) Sign(csr []byte, expiry time.Duration) (cert []byte, ca []by
return extractCertAndCA(createCertResp)
}

func NewSigner(ctx context.Context, spec *v1beta1.GoogleCASIssuerSpec, client client.Client, namespace string) (Signer, error) {
func NewSigner(ctx context.Context, spec *v1.GoogleCASIssuerSpec, client client.Client, namespace string) (Signer, error) {
c, err := newSignerNoSelftest(ctx, spec, client, namespace)
if err != nil {
return c, err
Expand All @@ -99,7 +99,7 @@ func NewSigner(ctx context.Context, spec *v1beta1.GoogleCASIssuerSpec, client cl
}

// newSignerNoSelftest creates a Signer without doing a self-check, useful for tests
func newSignerNoSelftest(ctx context.Context, spec *v1beta1.GoogleCASIssuerSpec, client client.Client, namespace string) (*casSigner, error) {
func newSignerNoSelftest(ctx context.Context, spec *v1.GoogleCASIssuerSpec, client client.Client, namespace string) (*casSigner, error) {
if spec.CaPoolId == "" {
return nil, fmt.Errorf("must specify a CaPoolId")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cas/cas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"google.golang.org/genproto/googleapis/cloud/security/privateca/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/jetstack/google-cas-issuer/api/v1beta1"
"github.com/jetstack/google-cas-issuer/api/v1"
)

func TestNewSigner(t *testing.T) {
spec := &v1beta1.GoogleCASIssuerSpec{
spec := &v1.GoogleCASIssuerSpec{
CaPoolId: "test-pool",
Project: "test-project",
Location: "test-location",
Expand All @@ -51,7 +51,7 @@ func TestNewSigner(t *testing.T) {
}

func TestNewSignerMissingPoolId(t *testing.T) {
spec := &v1beta1.GoogleCASIssuerSpec{
spec := &v1.GoogleCASIssuerSpec{
CaPoolId: "",
}
ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

casapi "github.com/jetstack/google-cas-issuer/api/v1beta1"
casapi "github.com/jetstack/google-cas-issuer/api/v1"
)

const (
Expand Down
30 changes: 15 additions & 15 deletions pkg/controller/issuer/googlecasissuer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

issuersv1beta1 "github.com/jetstack/google-cas-issuer/api/v1beta1"
issuersv1 "github.com/jetstack/google-cas-issuer/api/v1"
)

const (
Expand Down Expand Up @@ -82,7 +82,7 @@ func (r *GoogleCASIssuerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
// Always attempt to update the Ready condition
defer func() {
if err != nil {
setReadyCondition(status, issuersv1beta1.ConditionFalse, "issuer failed to reconcile", err.Error())
setReadyCondition(status, issuersv1.ConditionFalse, "issuer failed to reconcile", err.Error())
}
// If the Issuer is deleted mid-reconcile, ignore it
if updateErr := client.IgnoreNotFound(r.Status().Update(ctx, issuer)); updateErr != nil {
Expand All @@ -100,14 +100,14 @@ func (r *GoogleCASIssuerReconciler) Reconcile(ctx context.Context, req ctrl.Requ

if err != nil {
log.Info("Issuer is misconfigured", "info", err.Error())
setReadyCondition(status, issuersv1beta1.ConditionFalse, reasonIssuerMisconfigured, err.Error())
setReadyCondition(status, issuersv1.ConditionFalse, reasonIssuerMisconfigured, err.Error())
r.Recorder.Event(issuer, eventTypeWarning, reasonIssuerMisconfigured, err.Error())
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}

log.Info("reconciled issuer", "kind", issuer.GetObjectKind())
msg := "Successfully constructed CAS client"
setReadyCondition(status, issuersv1beta1.ConditionTrue, reasonCASClientOK, msg)
setReadyCondition(status, issuersv1.ConditionTrue, reasonCASClientOK, msg)
r.Recorder.Event(issuer, eventTypeNormal, reasonCASClientOK, msg)
return ctrl.Result{}, nil
}
Expand All @@ -124,41 +124,41 @@ func (r *GoogleCASIssuerReconciler) SetupWithManager(mgr ctrl.Manager) error {

// convert a k8s.io/apimachinery/pkg/runtime.Object into a sigs.k8s.io/controller-runtime/pkg/client.Object
func (r *GoogleCASIssuerReconciler) getIssuer() (client.Object, error) {
issuer, err := r.Scheme.New(issuersv1beta1.GroupVersion.WithKind(r.Kind))
issuer, err := r.Scheme.New(issuersv1.GroupVersion.WithKind(r.Kind))
if err != nil {
return nil, err
}
switch t := issuer.(type) {
case *issuersv1beta1.GoogleCASIssuer:
case *issuersv1.GoogleCASIssuer:
return t, nil
case *issuersv1beta1.GoogleCASClusterIssuer:
case *issuersv1.GoogleCASClusterIssuer:
return t, nil
default:
return nil, fmt.Errorf("unsupported kind %s", r.Kind)
}
}

func getIssuerSpecStatus(object client.Object) (*issuersv1beta1.GoogleCASIssuerSpec, *issuersv1beta1.GoogleCASIssuerStatus, error) {
func getIssuerSpecStatus(object client.Object) (*issuersv1.GoogleCASIssuerSpec, *issuersv1.GoogleCASIssuerStatus, error) {
switch t := object.(type) {
case *issuersv1beta1.GoogleCASIssuer:
case *issuersv1.GoogleCASIssuer:
return &t.Spec, &t.Status, nil
case *issuersv1beta1.GoogleCASClusterIssuer:
case *issuersv1.GoogleCASClusterIssuer:
return &t.Spec, &t.Status, nil
default:
return nil, nil, fmt.Errorf("unexpected type %T", t)
}
}

func setReadyCondition(status *issuersv1beta1.GoogleCASIssuerStatus, conditionStatus issuersv1beta1.ConditionStatus, reason, message string) {
var ready *issuersv1beta1.GoogleCASIssuerCondition
func setReadyCondition(status *issuersv1.GoogleCASIssuerStatus, conditionStatus issuersv1.ConditionStatus, reason, message string) {
var ready *issuersv1.GoogleCASIssuerCondition
for _, c := range status.Conditions {
if c.Type == issuersv1beta1.IssuerConditionReady {
if c.Type == issuersv1.IssuerConditionReady {
ready = &c
break
}
}
if ready == nil {
ready = &issuersv1beta1.GoogleCASIssuerCondition{Type: issuersv1beta1.IssuerConditionReady}
ready = &issuersv1.GoogleCASIssuerCondition{Type: issuersv1.IssuerConditionReady}
}
if ready.Status != conditionStatus {
ready.Status = conditionStatus
Expand All @@ -169,7 +169,7 @@ func setReadyCondition(status *issuersv1beta1.GoogleCASIssuerStatus, conditionSt
ready.Message = message

for i, c := range status.Conditions {
if c.Type == issuersv1beta1.IssuerConditionReady {
if c.Type == issuersv1.IssuerConditionReady {
status.Conditions[i] = *ready
return
}
Expand Down
Loading