Skip to content

Commit

Permalink
fix(yurt-manager): raven controller can't list calico blockaffinity (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
luckymrwang authored Sep 20, 2023
1 parent f782021 commit 424dcc2
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pkg/apis/addtoscheme_raven_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ limitations under the License.
package apis

import (
v3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"

v3 "github.com/openyurtio/openyurt/pkg/apis/calico/v3"
version "github.com/openyurtio/openyurt/pkg/apis/raven/v1alpha1"
)

Expand Down
82 changes: 82 additions & 0 deletions pkg/apis/calico/v3/blockaffinity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2023 The OpenYurt 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 v3

import (
apiv3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
KindBlockAffinity = "BlockAffinity"
KindBlockAffinityList = "BlockAffinityList"
)

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

// BlockAffinity maintains a block affinity's state
type BlockAffinity struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the BlockAffinity.
Spec BlockAffinitySpec `json:"spec,omitempty"`
}

// BlockAffinitySpec contains the specification for a BlockAffinity resource.
type BlockAffinitySpec struct {
State string `json:"state"`
Node string `json:"node"`
CIDR string `json:"cidr"`

// Deleted indicates that this block affinity is being deleted.
// This field is a string for compatibility with older releases that
// mistakenly treat this field as a string.
Deleted string `json:"deleted"`
}

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

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

// NewBlockAffinity creates a new (zeroed) BlockAffinity struct with the TypeMetadata initialised to the current
// version.
func NewBlockAffinity() *BlockAffinity {
return &BlockAffinity{
TypeMeta: metav1.TypeMeta{
Kind: KindBlockAffinity,
APIVersion: apiv3.GroupVersionCurrent,
},
}
}

// NewBlockAffinityList creates a new (zeroed) BlockAffinityList struct with the TypeMetadata initialised to the current
// version.
func NewBlockAffinityList() *BlockAffinityList {
return &BlockAffinityList{
TypeMeta: metav1.TypeMeta{
Kind: KindBlockAffinityList,
APIVersion: apiv3.GroupVersionCurrent,
},
}
}
53 changes: 53 additions & 0 deletions pkg/apis/calico/v3/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2023 The OpenYurt 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 v3

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

var SchemeGroupVersion = schema.GroupVersion{Group: "crd.projectcalico.org", Version: "v1"}

var (
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}

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

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion, []runtime.Object{
&BlockAffinity{},
&BlockAffinityList{},
}...)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
102 changes: 102 additions & 0 deletions pkg/apis/calico/v3/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"strings"
"time"

calicov3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -42,6 +41,7 @@ import (

appconfig "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
"github.com/openyurtio/openyurt/cmd/yurt-manager/names"
calicov3 "github.com/openyurtio/openyurt/pkg/apis/calico/v3"
"github.com/openyurtio/openyurt/pkg/apis/raven"
ravenv1beta1 "github.com/openyurtio/openyurt/pkg/apis/raven/v1beta1"
common "github.com/openyurtio/openyurt/pkg/yurtmanager/controller/raven"
Expand Down

0 comments on commit 424dcc2

Please sign in to comment.