Skip to content
This repository was archived by the owner on Jul 24, 2022. It is now read-only.
This repository was archived by the owner on Jul 24, 2022. It is now read-only.

自定义crd,types的struct中引用istio的vs,使用controller-gen生成crd yaml时,报错 #1

Description

@sayicui

自定义crd,types的struct中引用istio的vs,使用controller-gen生成crd yaml时,报错:

$ go run ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/servicemesh/... rbac:roleName=controller-perms crd
 output:crd:artifacts:config=config/crds
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\virtual_service.pb.go:1923:2: encountered struct field "MatchType" without JSON tag in type "St
ringMatch"
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\virtual_service.pb.go:1148:21: map values must be a named type, not *ast.StarExpr
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\virtual_service.pb.go:1172:25: map values must be a named type, not *ast.StarExpr
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\virtual_service.pb.go:2353:2: encountered struct field "HttpDelayType" without JSON tag in type
 "HTTPFaultInjection_Delay"
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\virtual_service.pb.go:2656:23: unsupported type "float64"
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\virtual_service.pb.go:2491:2: encountered struct field "ErrorType" without JSON tag in type "HT
TPFaultInjection_Abort"
F:\work\goWork\pkg\mod\istio.io\api@v0.0.0-20191111210003-35e06ef8d838\networking\v1alpha3\destination_rule.pb.go:667:2: encountered struct field "LbPolicy" without JSON tag in type "Loa
dBalancerSettings"
Error: not all generators ran successfully
run `controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/servicemesh/... rbac:roleName=controller-perms crd output:crd:artifacts:config=config/crds -w` to see all
 available markers, or `controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/servicemesh/... rbac:roleName=controller-perms crd output:crd:artifacts:config=config/
crds -h` for usage
exit status 1

定义结构体如下:


package v1alpha2

import (
	"istio.io/api/networking/v1alpha3"
	"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
	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.

const (
	ResourceKindStrategy     = "Strategy"
	ResourceSingularStrategy = "strategy"
	ResourcePluralStrategy   = "strategies"
)

type StrategyType string

const (
	// Canary strategy type
	CanaryType StrategyType = "Canary"

	// BlueGreen strategy type
	BlueGreenType StrategyType = "BlueGreen"

	// Mirror strategy type
	Mirror StrategyType = "Mirror"
)

type StrategyPolicy string

const (
	// apply strategy only until workload is ready
	PolicyWaitForWorkloadReady StrategyPolicy = "WaitForWorkloadReady"

	// apply strategy immediately no matter workload status is
	PolicyImmediately StrategyPolicy = "Immediately"

	// pause strategy
	PolicyPause StrategyPolicy = "Paused"
)

// StrategySpec defines the desired state of Strategy
type StrategySpec struct {
	// Strategy type
	Type StrategyType `json:"type,omitempty"`

	// Principal version, the one as reference version
	// label version value
	// +optional
	PrincipalVersion string `json:"principal,omitempty"`

	// Governor version, the version takes control of all incoming traffic
	// label version value
	// +optional
	GovernorVersion string `json:"governor,omitempty"`

	// Label selector for virtual services.
	// +optional
	Selector *metav1.LabelSelector `json:"selector,omitempty"`

	// Template describes the virtual service that will be created.
	Template VirtualServiceTemplateSpec `json:"template,omitempty"`

	// strategy policy, how the strategy will be applied
	// by the strategy controller
	StrategyPolicy StrategyPolicy `json:"strategyPolicy,omitempty"`
}

// VirtualServiceTemplateSpec
type VirtualServiceTemplateSpec struct {

	// Metadata of the virtual services created from this template
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty"`

	// Spec indicates the behavior of a virtual service.
	// +optional
	Spec v1alpha3.VirtualService `json:"spec,omitempty"`
}

// StrategyStatus defines the observed state of Strategy
type StrategyStatus struct {
	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
	// Important: Run "make" to regenerate code after modifying this file

	// The latest available observations of an object's current state.
	// +optional
	Conditions []StrategyCondition `json:"conditions,omitempty"`

	// Represents time when the strategy was acknowledged by the controller.
	// It is represented in RFC3339 form and is in UTC.
	// +optional
	StartTime *metav1.Time `json:"startTime,omitempty"`

	// Represents time when the strategy was completed.
	// It is represented in RFC3339 form and is in UTC.
	// +optional
	CompletionTime *metav1.Time `json:"completionTime,omitempty"`
}

type StrategyConditionType string

// These are valid conditions of a strategy.
const (
	// StrategyComplete means the strategy has been delivered to istio.
	StrategyComplete StrategyConditionType = "Complete"

	// StrategyFailed means the strategy has failed its delivery to istio.
	StrategyFailed StrategyConditionType = "Failed"
)

// StrategyCondition describes current state of a strategy.
type StrategyCondition struct {
	// Type of strategy condition, Complete or Failed.
	Type StrategyConditionType `json:"type,omitempty"`

	// Status of the condition, one of True, False, Unknown
	Status apiextensions.ConditionStatus `json:"status,omitempty"`

	// Last time the condition was checked.
	// +optional
	LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`

	// Last time the condition transit from one status to another
	// +optional
	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`

	// reason for the condition's last transition
	Reason string `json:"reason,omitempty"`

	// Human readable message indicating details about last transition.
	// +optinal
	Message string `json:"message,omitempty"`
}

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

// Strategy is the Schema for the strategies API
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type",description="type of strategy"
// +kubebuilder:printcolumn:name="Hosts",type="string",JSONPath=".spec.template.spec.hosts",description="destination hosts"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata"
// +k8s:openapi-gen=true
type Strategy struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   StrategySpec   `json:"spec,omitempty"`
	Status StrategyStatus `json:"status,omitempty"`
}

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

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

func init() {
	SchemeBuilder.Register(&Strategy{}, &StrategyList{})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions