Skip to content

Commit

Permalink
Merge pull request #1154 from swetharepakula/neg-crd
Browse files Browse the repository at this point in the history
Add NEG CRD definition
  • Loading branch information
k8s-ci-robot authored Jun 26, 2020
2 parents e33650b + df196b2 commit 1265e68
Show file tree
Hide file tree
Showing 29 changed files with 1,918 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,18 @@ ${GOPATH}/bin/openapi-gen \
--input-dirs k8s.io/ingress-gce/pkg/apis/frontendconfig/v1beta1\
--output-package k8s.io/ingress-gce/pkg/apis/frontendconfig/v1beta1 \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

echo "Performing code generation for ServiceNetworkEndpointGroup CRD"
${CODEGEN_PKG}/generate-groups.sh \
"deepcopy,client,informer,lister" \
k8s.io/ingress-gce/pkg/svcneg/client k8s.io/ingress-gce/pkg/apis \
"svcneg:v1beta1" \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

echo "Generating openapi for ServiceNetworkEndpointGroup v1beta1"
go install ${OPENAPI_PKG}/cmd/openapi-gen
${GOPATH}/bin/openapi-gen \
--output-file-base zz_generated.openapi \
--input-dirs k8s.io/ingress-gce/pkg/apis/svcneg/v1beta1\
--output-package k8s.io/ingress-gce/pkg/apis/svcneg/v1beta1 \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt
21 changes: 21 additions & 0 deletions pkg/apis/svcneg/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2020 The Kubernetes 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 svcneg

const (
GroupName = "networking.gke.io"
)
21 changes: 21 additions & 0 deletions pkg/apis/svcneg/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2020 The Kubernetes 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.
*/

// +k8s:deepcopy-gen=package

// Package v1beta1 is the v1beta1 version of the API.
// +groupName=networking.gke.io
package v1beta1
52 changes: 52 additions & 0 deletions pkg/apis/svcneg/v1beta1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2020 The Kubernetes 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 v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/ingress-gce/pkg/apis/svcneg"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: svcneg.GroupName, Version: "v1beta1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ServiceNetworkEndpointGroup{},
&ServiceNetworkEndpointGroupList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
118 changes: 118 additions & 0 deletions pkg/apis/svcneg/v1beta1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
Copyright 2020 The Kubernetes 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 v1beta1

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

// ServiceNetworkEndpointGroup represents a group of Network Endpoint Groups associated with a service.

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
//
// +k8s:openapi-gen=true
type ServiceNetworkEndpointGroup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ServiceNetworkEndpointGroupSpec `json:"spec,omitempty"`
Status ServiceNetworkEndpointGroupStatus `json:"status,omitempty"`
}

// ServiceNetworkEndpointGroupSpec is the spec for a ServiceNetworkEndpointGroup resource
// +k8s:openapi-gen=true
type ServiceNetworkEndpointGroupSpec struct{}

// ServiceNetworkEndpointGroupStatus is the status for a ServiceNetworkEndpointGroup resource
type ServiceNetworkEndpointGroupStatus struct {
NetworkEndpointGroups []NegObjectReference `json:"networkEndpointGroups,omitempty"`

// Last time the NEG syncer syncs associated NEGs.
// +optional
Conditions []Condition `json:"conditions,omitempty"`

// Last time the NEG syncer syncs associated NEGs.
// +optional
LastSyncTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// NegObjectReference is the object reference to the NEG resource in GCE
type NegObjectReference struct {
// The unique identifier for the NEG resource in GCE API.
Id uint64 `json:"id,omitempty,string"`

// SelfLink is the GCE Server-defined fully-qualified URL for the GCE NEG resource
SelfLink string `json:"selfLink,omitempty"`

// NetworkEndpointType: Type of network endpoints in this network
// endpoint group.
NetworkEndpointType NetworkEndpointType `json:"networkEndpointType,omitempty"`
}

type NetworkEndpointType string

const (
VmIpPortEndpointType = NetworkEndpointType("GCE_VM_IP_PORT")
VmIpEndpointType = NetworkEndpointType("GCE_VM_IP")
NonGCPPrivateEndpointType = NetworkEndpointType("NON_GCP_PRIVATE_IP_PORT")
)

// TODO: Replace Condition with standard Condition
// NegCondition contains details for the current condition of this NEG.
type Condition struct {
// Type is the type of the condition.
// +required
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
// Status of the condition, one of True, False, Unknown.
// +required
Status core.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status"`
// ObservedGeneration will not be set for ServiceNetworkEndpointGroup as the spec is empty.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
// Last time the condition transitioned from one status to another.
// +required
LastTransitionTime metav1.Time `json:"lastTransitionTime" protobuf:"bytes,4,opt,name=lastTransitionTime"`
// The reason for the condition's last transition
// +required
Reason string `json:"reason" protobuf:"bytes,5,opt,name=reason"`
// A human readable message indicating details about the transition.
// This field may be empty.
// +required
Message string `json:"message" protobuf:"bytes,6,opt,name=message"`
}

// These are valid conditions of NEG.
const (
// Initialized means all NEGs have been created and initialized.
Initialized = "Initialized"
// Synced means all NEGs are being synced.
// The LastSyncTime represents the time when the last sync took place.
Synced = "Synced"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ServiceNetworkEndpointGroupList is a list of ServiceNetworkEndpointGroup resources
type ServiceNetworkEndpointGroupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []ServiceNetworkEndpointGroup `json:"items"`
}
164 changes: 164 additions & 0 deletions pkg/apis/svcneg/v1beta1/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 1265e68

Please sign in to comment.