Skip to content

Commit

Permalink
feat: add API-resource Group (#17)
Browse files Browse the repository at this point in the history
* feat: add API-resource Group

* chore: register group type

* fix: name collision Group

* chore: go mod tidy

* chore: generate files

* fix: spacing in apis/user/v1alpha1/groupversion_info.go

Co-authored-by: Amund Tenstad <[email protected]>

* lint: run gofmt -s -w on go files failing lint

---------

Co-authored-by: Amund Tenstad <[email protected]>
  • Loading branch information
mariatsji and tenstad authored Nov 25, 2024
1 parent 9ea0c6f commit 2321631
Show file tree
Hide file tree
Showing 14 changed files with 1,020 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apis/cloudian.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ package apis
import (
"k8s.io/apimachinery/pkg/runtime"

userv1alpha1 "github.com/statnett/provider-cloudian/apis/user/v1alpha1"
cloudianv1alpha1 "github.com/statnett/provider-cloudian/apis/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes,
cloudianv1alpha1.SchemeBuilder.AddToScheme,
userv1alpha1.SchemeBuilder.AddToScheme,
)
}

Expand Down
18 changes: 18 additions & 0 deletions apis/user/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 The Crossplane Authors.
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 user contains group user API versions
package user
17 changes: 17 additions & 0 deletions apis/user/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2022 The Crossplane Authors.
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 v1alpha1
86 changes: 86 additions & 0 deletions apis/user/v1alpha1/group_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright 2022 The Crossplane Authors.
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 v1alpha1

import (
"reflect"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// GroupParameters are the configurable fields of a Group.
type GroupParameters struct {
ConfigurableField string `json:"configurableField"`
}

// GroupObservation are the observable fields of a Group.
type GroupObservation struct {
ObservableField string `json:"observableField,omitempty"`
}

// A GroupSpec defines the desired state of a Group.
type GroupSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider GroupParameters `json:"forProvider"`
}

// A GroupStatus represents the observed state of a Group.
type GroupStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider GroupObservation `json:"atProvider,omitempty"`
}

// +kubebuilder:object:root=true

// A Group is an example API type.
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,cloudian}
type Group struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GroupSpec `json:"spec"`
Status GroupStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// GroupList contains a list of Group
type GroupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Group `json:"items"`
}

// Group type metadata.
var (
GroupKind = reflect.TypeOf(Group{}).Name()
GroupGroupKind = schema.GroupKind{Group: MetadataGroup, Kind: GroupKind}.String()
GroupKindAPIVersion = GroupKind + "." + SchemeGroupVersion.String()
GroupGroupVersionKind = SchemeGroupVersion.WithKind(GroupKind)
)

func init() {
SchemeBuilder.Register(&Group{}, &GroupList{})
}
40 changes: 40 additions & 0 deletions apis/user/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2020 The Crossplane Authors.
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 v1alpha1 contains the v1alpha1 group Sample resources of the Cloudian provider.
// +kubebuilder:object:generate=true
// +groupName=user.cloudian.crossplane.io
// +versionName=v1alpha1
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

// Package type metadata.
const (
MetadataGroup = "user.cloudian.crossplane.io"
Version = "v1alpha1"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: MetadataGroup, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
)
148 changes: 148 additions & 0 deletions apis/user/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 2321631

Please sign in to comment.