diff --git a/.travis.yml b/.travis.yml index 6fe26f3f..63271d93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ install: - rsync -az ${TRAVIS_BUILD_DIR}/ $GOPATH/src/github.com/autonomy/conform/ - export TRAVIS_BUILD_DIR=$GOPATH/src/github.com/autonomy/conform - cd $GOPATH/src/github.com/autonomy/conform + - sudo rm -rf /etc/apt/sources.list.d - sudo apt-get -y remove docker docker-engine - sudo apt-get -y update - sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common @@ -23,10 +24,11 @@ install: - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - sudo apt-get update - sudo apt-get -y install docker-ce + - echo "$DOCKER_TOKEN" | docker login --username "$DOCKER_USERNAME" --password-stdin script: - - make + - make VERSION=latest after_success: - - docker run --volume=$(pwd):/out --entrypoint=cp logicmonitor/argus:latest /coverage.txt /out + - docker run --volume=$(pwd):/out --entrypoint=cp logicmonitor/collectorset-controller:latest /coverage.txt /out - bash <(curl -s https://codecov.io/bash) diff --git a/Dockerfile b/Dockerfile index dd75f038..2453d411 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN curl -L https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3 COPY ./proto ./proto RUN mkdir api RUN protoc -I proto proto/api.proto \ - --go_out=plugins=grpc:api + --go_out=plugins=grpc:api --go_opt=paths=source_relative FROM golang:1.14-alpine as codegen RUN apk add --update git @@ -21,13 +21,14 @@ WORKDIR $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller COPY ./ ./ RUN deepcopy-gen \ --go-header-file="hack/boilerplate.go.txt" \ - --input-dirs="github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" \ - --bounding-dirs "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" \ + --input-dirs="github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" \ + --bounding-dirs "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" \ --output-file-base zz_generated.deepcopy FROM golang:1.14 as build WORKDIR $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller COPY --from=codegen $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller ./ +COPY --from=api $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller/api ./api ARG VERSION RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /collectorset-controller -ldflags "-X \"github.com/logicmonitor/k8s-collectorset-controller/pkg/constants.Version=${VERSION}\"" @@ -46,7 +47,7 @@ RUN apk --update add ca-certificates \ && rm -rf /var/lib/apk/* WORKDIR /app COPY --from=api /go/src/github.com/logicmonitor/k8s-collectorset-controller/api/* /tmp/ -COPY --from=codegen /go/src/github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1/zz_generated.deepcopy.go /tmp/ +COPY --from=codegen /go/src/github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2/zz_generated.deepcopy.go /tmp/ COPY --from=build /collectorset-controller /bin COPY --from=test /coverage.txt /coverage.txt diff --git a/Dockerfile.dev b/Dockerfile.dev index ae79c9f2..b1e3f88a 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -8,7 +8,7 @@ RUN curl -L https://github.com/google/protobuf/releases/download/v3.3.0/protoc-3 COPY ./proto ./proto RUN mkdir api RUN protoc -I proto proto/api.proto \ - --go_out=plugins=grpc:api + --go_out=plugins=grpc:api --go_opt=paths=source_relative FROM golang:1.14-alpine as codegen RUN apk add --update git @@ -21,13 +21,14 @@ WORKDIR $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller COPY ./ ./ RUN deepcopy-gen \ --go-header-file="hack/boilerplate.go.txt" \ - --input-dirs="github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" \ - --bounding-dirs "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" \ + --input-dirs="github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" \ + --bounding-dirs "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" \ --output-file-base zz_generated.deepcopy FROM golang:1.14 as build WORKDIR $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller COPY --from=codegen $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller ./ +COPY --from=api $GOPATH/src/github.com/logicmonitor/k8s-collectorset-controller/api ./api ARG VERSION RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /collectorset-controller -ldflags "-X \"github.com/logicmonitor/k8s-collectorset-controller/pkg/constants.Version=${VERSION}\"" @@ -38,7 +39,7 @@ RUN apk --update add ca-certificates \ && rm -rf /var/lib/apk/* WORKDIR /app COPY --from=api /go/src/github.com/logicmonitor/k8s-collectorset-controller/api/* /tmp/ -COPY --from=codegen /go/src/github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1/zz_generated.deepcopy.go /tmp/ +COPY --from=codegen /go/src/github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2/zz_generated.deepcopy.go /tmp/ COPY --from=build /collectorset-controller /bin ENTRYPOINT ["collectorset-controller"] diff --git a/Makefile b/Makefile index b9c86270..a9d0e8ef 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,34 @@ NAMESPACE := logicmonitor REPOSITORY := collectorset-controller VERSION := 1.0.0 -all: - docker build --build-arg VERSION=$(VERSION) -t $(NAMESPACE)/$(REPOSITORY):v2latest . - docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):v2latest /tmp/api.pb.go /out/api - docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):v2latest /tmp/zz_generated.deepcopy.go /out/pkg/apis/v1alpha1/ - docker tag $(NAMESPACE)/$(REPOSITORY):v2latest $(NAMESPACE)/$(REPOSITORY):$(VERSION) -dev: - docker build --build-arg VERSION=$(VERSION) -t $(NAMESPACE)/$(REPOSITORY):v2latest -f Dockerfile.dev . - docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):v2latest /tmp/api.pb.go /out/api - docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):v2latest /tmp/zz_generated.deepcopy.go /out/pkg/apis/v1alpha1/ - docker tag $(NAMESPACE)/$(REPOSITORY):v2latest $(NAMESPACE)/$(REPOSITORY):$(VERSION) +default: build + +gofmt: +ifeq ($(shell uname -s), Darwin) + find pkg/ -type f | grep go | egrep -v "mocks|gomock" | xargs gofmt -l -d -s -w; sync + find pkg/ -type f | grep go | egrep -v "mocks|gomock" | xargs gofumpt -l -d -s -w; sync + find pkg/ -type f | grep go | egrep -v "mocks|gomock" | xargs gci -w; sync + find pkg/ -type f | grep go | egrep -v "mocks|gomock" | xargs goimports -l -d -w; sync + find cmd/ -type f | grep go | egrep -v "mocks|gomock" | xargs gofmt -l -d -s -w; sync + find cmd/ -type f | grep go | egrep -v "mocks|gomock" | xargs gofumpt -l -d -s -w; sync + find cmd/ -type f | grep go | egrep -v "mocks|gomock" | xargs gci -w; sync + find cmd/ -type f | grep go | egrep -v "mocks|gomock" | xargs goimports -l -d -w; sync + gofmt -l -d -s -w main.go; sync + gofumpt -l -d -s -w main.go; sync + gci -w main.go; sync + goimports -l -d -w main.go; sync +endif + +build: gofmt + docker build --build-arg VERSION=$(VERSION) -t $(NAMESPACE)/$(REPOSITORY):latest . + docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):latest /tmp/api.pb.go /out/api + docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):latest /tmp/zz_generated.deepcopy.go /out/pkg/apis/v1alpha2/ + docker tag $(NAMESPACE)/$(REPOSITORY):latest $(NAMESPACE)/$(REPOSITORY):$(VERSION) + +dev: gofmt + docker build --build-arg VERSION=$(VERSION) -t $(NAMESPACE)/$(REPOSITORY):latest -f Dockerfile.dev . + docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):latest /tmp/api.pb.go /out/api + docker run --rm -v "$(shell pwd)":/out --entrypoint=cp $(NAMESPACE)/$(REPOSITORY):latest /tmp/zz_generated.deepcopy.go /out/pkg/apis/v1alpha2/ + docker tag $(NAMESPACE)/$(REPOSITORY):latest $(NAMESPACE)/$(REPOSITORY):$(VERSION) + + diff --git a/api/api.pb.go b/api/api.pb.go index bc9cba68..df08d058 100644 --- a/api/api.pb.go +++ b/api/api.pb.go @@ -1,130 +1,223 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1-devel +// protoc v3.3.0 // source: api.proto package api import ( context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - math "math" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) // The request message for a collector ID. type CollectorIDRequest struct { - Orchestrator string `protobuf:"bytes,2,opt,name=orchestrator,proto3" json:"orchestrator,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *CollectorIDRequest) Reset() { *m = CollectorIDRequest{} } -func (m *CollectorIDRequest) String() string { return proto.CompactTextString(m) } -func (*CollectorIDRequest) ProtoMessage() {} -func (*CollectorIDRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_00212fb1f9d3bf1c, []int{0} + Orchestrator string `protobuf:"bytes,2,opt,name=orchestrator,proto3" json:"orchestrator,omitempty"` } -func (m *CollectorIDRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CollectorIDRequest.Unmarshal(m, b) -} -func (m *CollectorIDRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CollectorIDRequest.Marshal(b, m, deterministic) -} -func (m *CollectorIDRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_CollectorIDRequest.Merge(m, src) +func (x *CollectorIDRequest) Reset() { + *x = CollectorIDRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *CollectorIDRequest) XXX_Size() int { - return xxx_messageInfo_CollectorIDRequest.Size(m) + +func (x *CollectorIDRequest) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *CollectorIDRequest) XXX_DiscardUnknown() { - xxx_messageInfo_CollectorIDRequest.DiscardUnknown(m) + +func (*CollectorIDRequest) ProtoMessage() {} + +func (x *CollectorIDRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_CollectorIDRequest proto.InternalMessageInfo +// Deprecated: Use CollectorIDRequest.ProtoReflect.Descriptor instead. +func (*CollectorIDRequest) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{0} +} -func (m *CollectorIDRequest) GetOrchestrator() string { - if m != nil { - return m.Orchestrator +func (x *CollectorIDRequest) GetOrchestrator() string { + if x != nil { + return x.Orchestrator } return "" } // The response message from a collector ID request. type CollectorIDReply struct { - Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *CollectorIDReply) Reset() { *m = CollectorIDReply{} } -func (m *CollectorIDReply) String() string { return proto.CompactTextString(m) } -func (*CollectorIDReply) ProtoMessage() {} -func (*CollectorIDReply) Descriptor() ([]byte, []int) { - return fileDescriptor_00212fb1f9d3bf1c, []int{1} + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` } -func (m *CollectorIDReply) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CollectorIDReply.Unmarshal(m, b) -} -func (m *CollectorIDReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CollectorIDReply.Marshal(b, m, deterministic) -} -func (m *CollectorIDReply) XXX_Merge(src proto.Message) { - xxx_messageInfo_CollectorIDReply.Merge(m, src) +func (x *CollectorIDReply) Reset() { + *x = CollectorIDReply{} + if protoimpl.UnsafeEnabled { + mi := &file_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *CollectorIDReply) XXX_Size() int { - return xxx_messageInfo_CollectorIDReply.Size(m) + +func (x *CollectorIDReply) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *CollectorIDReply) XXX_DiscardUnknown() { - xxx_messageInfo_CollectorIDReply.DiscardUnknown(m) + +func (*CollectorIDReply) ProtoMessage() {} + +func (x *CollectorIDReply) ProtoReflect() protoreflect.Message { + mi := &file_api_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_CollectorIDReply proto.InternalMessageInfo +// Deprecated: Use CollectorIDReply.ProtoReflect.Descriptor instead. +func (*CollectorIDReply) Descriptor() ([]byte, []int) { + return file_api_proto_rawDescGZIP(), []int{1} +} -func (m *CollectorIDReply) GetId() int32 { - if m != nil { - return m.Id +func (x *CollectorIDReply) GetId() int32 { + if x != nil { + return x.Id } return 0 } -func init() { - proto.RegisterType((*CollectorIDRequest)(nil), "api.CollectorIDRequest") - proto.RegisterType((*CollectorIDReply)(nil), "api.CollectorIDReply") +var File_api_proto protoreflect.FileDescriptor + +var file_api_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, + 0x22, 0x38, 0x0a, 0x12, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x44, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x6f, 0x72, 0x63, 0x68, 0x65, 0x73, + 0x74, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x6f, 0x72, + 0x63, 0x68, 0x65, 0x73, 0x74, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x22, 0x22, 0x0a, 0x10, 0x43, 0x6f, + 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x44, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0e, + 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x32, 0x59, + 0x0a, 0x16, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x53, 0x65, 0x74, 0x43, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x12, 0x3f, 0x0a, 0x0b, 0x43, 0x6f, 0x6c, 0x6c, + 0x65, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x44, 0x12, 0x17, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, + 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x44, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x15, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, + 0x49, 0x44, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x39, 0x5a, 0x37, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x6f, 0x67, 0x69, 0x63, 0x6d, 0x6f, 0x6e, + 0x69, 0x74, 0x6f, 0x72, 0x2f, 0x6b, 0x38, 0x73, 0x2d, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, + 0x6f, 0x72, 0x73, 0x65, 0x74, 0x2d, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, + 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } -func init() { - proto.RegisterFile("api.proto", fileDescriptor_00212fb1f9d3bf1c) +var ( + file_api_proto_rawDescOnce sync.Once + file_api_proto_rawDescData = file_api_proto_rawDesc +) + +func file_api_proto_rawDescGZIP() []byte { + file_api_proto_rawDescOnce.Do(func() { + file_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_proto_rawDescData) + }) + return file_api_proto_rawDescData +} + +var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_api_proto_goTypes = []interface{}{ + (*CollectorIDRequest)(nil), // 0: api.CollectorIDRequest + (*CollectorIDReply)(nil), // 1: api.CollectorIDReply +} +var file_api_proto_depIdxs = []int32{ + 0, // 0: api.CollectorSetController.CollectorID:input_type -> api.CollectorIDRequest + 1, // 1: api.CollectorSetController.CollectorID:output_type -> api.CollectorIDReply + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } -var fileDescriptor_00212fb1f9d3bf1c = []byte{ - // 157 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0xb2, 0xe0, 0x12, 0x72, 0xce, - 0xcf, 0xc9, 0x49, 0x4d, 0x2e, 0xc9, 0x2f, 0xf2, 0x74, 0x09, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, - 0x11, 0x52, 0xe2, 0xe2, 0xc9, 0x2f, 0x4a, 0xce, 0x48, 0x2d, 0x2e, 0x29, 0x4a, 0x2c, 0xc9, 0x2f, - 0x92, 0x60, 0x52, 0x60, 0xd4, 0xe0, 0x0c, 0x42, 0x11, 0x53, 0x52, 0xe2, 0x12, 0x40, 0xd1, 0x59, - 0x90, 0x53, 0x29, 0xc4, 0xc7, 0xc5, 0x94, 0x99, 0x22, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x1a, 0xc4, - 0x94, 0x99, 0x62, 0x14, 0xc9, 0x25, 0x06, 0x57, 0x13, 0x9c, 0x5a, 0xe2, 0x9c, 0x9f, 0x57, 0x52, - 0x04, 0xe2, 0x17, 0x09, 0xd9, 0x73, 0x71, 0x23, 0xe9, 0x16, 0x12, 0xd7, 0x03, 0xb9, 0x0b, 0xd3, - 0x25, 0x52, 0xa2, 0x98, 0x12, 0x05, 0x39, 0x95, 0x4a, 0x0c, 0x49, 0x6c, 0x60, 0x4f, 0x18, 0x03, - 0x02, 0x00, 0x00, 0xff, 0xff, 0x31, 0xf4, 0x7e, 0x42, 0xd1, 0x00, 0x00, 0x00, +func init() { file_api_proto_init() } +func file_api_proto_init() { + if File_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CollectorIDRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CollectorIDReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_api_proto_goTypes, + DependencyIndexes: file_api_proto_depIdxs, + MessageInfos: file_api_proto_msgTypes, + }.Build() + File_api_proto = out.File + file_api_proto_rawDesc = nil + file_api_proto_goTypes = nil + file_api_proto_depIdxs = nil } // Reference imports to suppress errors if they are not otherwise used. @@ -170,7 +263,7 @@ type CollectorSetControllerServer interface { type UnimplementedCollectorSetControllerServer struct { } -func (*UnimplementedCollectorSetControllerServer) CollectorID(ctx context.Context, req *CollectorIDRequest) (*CollectorIDReply, error) { +func (*UnimplementedCollectorSetControllerServer) CollectorID(context.Context, *CollectorIDRequest) (*CollectorIDReply, error) { return nil, status.Errorf(codes.Unimplemented, "method CollectorID not implemented") } diff --git a/examples/collectorset.yaml b/examples/collectorset.yaml index 58965e1d..e2b0c2d8 100644 --- a/examples/collectorset.yaml +++ b/examples/collectorset.yaml @@ -1,4 +1,4 @@ -apiVersion: logicmonitor.com/v1alpha1 +apiVersion: logicmonitor.com/v1alpha2 kind: CollectorSet metadata: name: example diff --git a/go.mod b/go.mod index 3dbddcb2..7c4f4792 100644 --- a/go.mod +++ b/go.mod @@ -3,19 +3,18 @@ module github.com/logicmonitor/k8s-collectorset-controller go 1.14 require ( + github.com/daixiang0/gci v0.2.9 // indirect github.com/go-openapi/runtime v0.19.4 github.com/go-openapi/strfmt v0.19.3 github.com/golang/protobuf v1.4.2 github.com/googleapis/gnostic v0.4.0 // indirect github.com/kelseyhightower/envconfig v1.4.0 github.com/kr/pretty v0.2.0 // indirect + github.com/logicmonitor/lm-sdk-go v2.0.0+incompatible github.com/mitchellh/go-homedir v1.1.0 github.com/sirupsen/logrus v1.6.0 github.com/spf13/cobra v1.0.0 github.com/spf13/viper v1.7.1 - github.com/logicmonitor/lm-sdk-go v2.0.0+incompatible - golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect - golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect google.golang.org/grpc v1.27.0 google.golang.org/protobuf v1.25.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect @@ -24,4 +23,5 @@ require ( k8s.io/apiextensions-apiserver v0.17.0 k8s.io/apimachinery v0.17.0 k8s.io/client-go v0.17.0 + mvdan.cc/gofumpt v0.1.1 // indirect ) diff --git a/go.sum b/go.sum index bf6cc8c4..8ae234db 100644 --- a/go.sum +++ b/go.sum @@ -66,6 +66,8 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/daixiang0/gci v0.2.9 h1:iwJvwQpBZmMg31w+QQ6jsyZ54KEATn6/nfARbBNW294= +github.com/daixiang0/gci v0.2.9/go.mod h1:+4dZ7TISfSmqfAGv59ePaHfNzgGtIkHAhhdKggP1JAc= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -186,6 +188,8 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -268,6 +272,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/logicmonitor/lm-sdk-go v2.0.0+incompatible h1:g/8iONuJKtUWGQ3MVdSRXhE5ovtxF2voi4OCZFwEDDM= github.com/logicmonitor/lm-sdk-go v2.0.0+incompatible/go.mod h1:gpLvWtDkb4lq+ezlvG79A953MZHoq/3XLTff4AIUF+M= +github.com/logicmonitor/lm-sdk-go v2.0.1+incompatible h1:t1UbZZ1ju6wv6NRVf6lx9wu4hHEe/mneZxqYGwIq/O8= +github.com/logicmonitor/lm-sdk-go v2.0.1+incompatible/go.mod h1:svWOa+F9+4aChOCrhd5m2pZt7V1zx2VUkmCkkdjw7Lg= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -340,6 +346,7 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -397,10 +404,9 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= -github.com/logicmonitor/lm-sdk-go v2.0.1+incompatible h1:t1UbZZ1ju6wv6NRVf6lx9wu4hHEe/mneZxqYGwIq/O8= -github.com/logicmonitor/lm-sdk-go v2.0.1+incompatible/go.mod h1:svWOa+F9+4aChOCrhd5m2pZt7V1zx2VUkmCkkdjw7Lg= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= @@ -427,6 +433,7 @@ golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -447,6 +454,9 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0 h1:8pl+sMODzuvGJkmj2W4kZihvVb5mKm8pB/X44PIQHv8= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -472,6 +482,7 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= @@ -481,6 +492,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -504,11 +516,13 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= @@ -538,9 +552,15 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20201118003311-bd56c0adb394/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c h1:dS09fXwOFF9cXBnIzZexIuUBj95U1NyQjkEhkgidDow= +golang.org/x/tools v0.0.0-20210101214203-2dba1e4ea05c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ= @@ -637,6 +657,8 @@ modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs= modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I= +mvdan.cc/gofumpt v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA= +mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06/go.mod h1:/ULNhyfzRopfcjskuui0cTITekDduZ7ycKN3oUT9R18= diff --git a/pkg/apis/v1alpha1/register.go b/pkg/apis/v1alpha1/register.go index b464e36f..37376c7d 100644 --- a/pkg/apis/v1alpha1/register.go +++ b/pkg/apis/v1alpha1/register.go @@ -17,8 +17,10 @@ var ( const GroupName = "logicmonitor.com" // SchemeGroupVersion is the group version used to register these objects. -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} -var SchemeGroupVersionInternal = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} +var ( + SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + SchemeGroupVersionInternal = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} +) // Resource takes an unqualified resource and returns a Group-qualified GroupResource. func Resource(resource string) schema.GroupResource { @@ -37,6 +39,6 @@ func addKnownTypes(scheme *runtime.Scheme) error { &CollectorSet{}, &CollectorSetList{}, ) - //metav1.AddToGroupVersion(scheme, SchemeGroupVersionInternal) + // metav1.AddToGroupVersion(scheme, SchemeGroupVersionInternal) return nil } diff --git a/pkg/apis/v1alpha1/types.go b/pkg/apis/v1alpha1/types.go index ab49b110..66ddc0a6 100644 --- a/pkg/apis/v1alpha1/types.go +++ b/pkg/apis/v1alpha1/types.go @@ -40,10 +40,10 @@ type CollectorSetSpec struct { Replicas *int32 `json:"replicas"` Size string `json:"size,omitempty"` ClusterName string `json:"clusterName"` - GroupID int32 `json:"groupID,omitempty"` //default value is 0, it means no group is offered - EscalationChainID int32 `json:"escalationChainID,omitempty"` //default value is 0, it means disable notification - CollectorVersion int32 `json:"collectorVersion,omitempty"` //default value is 0, it means the latest GD version - UseEA bool `json:"useEA,omitempty"` //default value is false, it means the latest GD version + GroupID int32 `json:"groupID,omitempty"` // default value is 0, it means no group is offered + EscalationChainID int32 `json:"escalationChainID,omitempty"` // default value is 0, it means disable notification + CollectorVersion int32 `json:"collectorVersion,omitempty"` // default value is 0, it means the latest GD version + UseEA bool `json:"useEA,omitempty"` // default value is false, it means the latest GD version Policy *CollectorSetPolicy `json:"policy"` ProxyURL string `json:"proxyURL,omitempty"` SecretName string `json:"secretName,omitempty"` diff --git a/pkg/apis/v1alpha2/doc.go b/pkg/apis/v1alpha2/doc.go new file mode 100644 index 00000000..53726d30 --- /dev/null +++ b/pkg/apis/v1alpha2/doc.go @@ -0,0 +1,5 @@ +// Package v1alpha2 implements a Kubernetes CRD, and controller for LogicMonitor +// collectors. +// +k8s:deepcopy-gen=package +// +groupName=collectors.logicmonitor.com +package v1alpha2 diff --git a/pkg/apis/v1alpha2/register.go b/pkg/apis/v1alpha2/register.go new file mode 100644 index 00000000..789132d2 --- /dev/null +++ b/pkg/apis/v1alpha2/register.go @@ -0,0 +1,44 @@ +package v1alpha2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + // SchemeBuilder is a SchemeBuilder. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme is the SchemeBuilder AddToScheme function. + AddToScheme = SchemeBuilder.AddToScheme +) + +// GroupName is the group name used in this package. +const GroupName = "logicmonitor.com" + +// SchemeGroupVersion is the group version used to register these objects. +var ( + SchemaGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha2"} + SchemeGroupVersionInternal = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} +) + +// Resource takes an unqualified resource and returns a Group-qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemaGroupVersion.WithResource(resource).GroupResource() +} + +// addKnownTypes adds the set of types defined in this package to the supplied scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemaGroupVersion, + &CollectorSet{}, + &CollectorSetList{}, + ) + metav1.AddToGroupVersion(scheme, SchemaGroupVersion) + + scheme.AddKnownTypes(SchemeGroupVersionInternal, + &CollectorSet{}, + &CollectorSetList{}, + ) + // metav1.AddToGroupVersion(scheme, SchemeGroupVersionInternal) + return nil +} diff --git a/pkg/apis/v1alpha2/types.go b/pkg/apis/v1alpha2/types.go new file mode 100644 index 00000000..6be6eb9f --- /dev/null +++ b/pkg/apis/v1alpha2/types.go @@ -0,0 +1,70 @@ +package v1alpha2 + +import ( + "github.com/logicmonitor/k8s-collectorset-controller/pkg/distributor" + appsv1 "k8s.io/api/apps/v1" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// CollectorSetState is the CollectorSet controller's state string. +type CollectorSetState string + +const ( + // CollectorSetStateCreated is a status string. + CollectorSetStateCreated CollectorSetState = "Created" + // CollectorSetStateRegistered is a status string. + CollectorSetStateRegistered CollectorSetState = "Registered" + // CollectorSetResourcePlural is the plural for the CRD. + CollectorSetResourcePlural = "collectorsets" +) + +// CollectorSet represents the collectorset in Kubernetes. +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type CollectorSet struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec CollectorSetSpec `json:"spec"` + Status CollectorSetStatus `json:"status,omitempty"` +} + +// CollectorSetSpec represents the collectorset controller's spec. +type CollectorSetSpec struct { + Annotations map[string]string `json:"annotations,omitempty"` + Labels map[string]string `json:"labels,omitempty"` + CollectorStatefulSetSpec appsv1.StatefulSetSpec `json:"statefulsetspec,omitempty"` + ImageRepository string `json:"imageRepository"` + ImageTag string `json:"imageTag"` + ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy"` + Replicas *int32 `json:"replicas"` + Size string `json:"size,omitempty"` + ClusterName string `json:"clusterName"` + GroupID int32 `json:"groupID,omitempty"` // default value is 0, it means no group is offered + EscalationChainID int32 `json:"escalationChainID,omitempty"` // default value is 0, it means disable notification + CollectorVersion int32 `json:"collectorVersion,omitempty"` // default value is 0, it means the latest GD version + UseEA bool `json:"useEA,omitempty"` // default value is false, it means the latest GD version + Policy *CollectorSetPolicy `json:"policy"` + ProxyURL string `json:"proxyURL,omitempty"` + SecretName string `json:"secretName,omitempty"` +} + +// CollectorSetStatus is the CollectorSet controller's status. +type CollectorSetStatus struct { + State CollectorSetState `json:"state,omitempty"` + IDs []int32 `json:"ids,omitempty"` +} + +// CollectorSetPolicy is the CollectorSet controller's status. +type CollectorSetPolicy struct { + Orchestrator string `json:"orchestrator,omitempty"` + DistibutionStrategy *distributor.Type `json:"distributionStrategy"` +} + +// CollectorSetList represents a list of collectorsets. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type CollectorSetList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []CollectorSet `json:"items"` +} diff --git a/pkg/apis/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/v1alpha2/zz_generated.deepcopy.go new file mode 100644 index 00000000..fc55c4a9 --- /dev/null +++ b/pkg/apis/v1alpha2/zz_generated.deepcopy.go @@ -0,0 +1,154 @@ +// +build !ignore_autogenerated + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + distributor "github.com/logicmonitor/k8s-collectorset-controller/pkg/distributor" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CollectorSet) DeepCopyInto(out *CollectorSet) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectorSet. +func (in *CollectorSet) DeepCopy() *CollectorSet { + if in == nil { + return nil + } + out := new(CollectorSet) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CollectorSet) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CollectorSetList) DeepCopyInto(out *CollectorSetList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]CollectorSet, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectorSetList. +func (in *CollectorSetList) DeepCopy() *CollectorSetList { + if in == nil { + return nil + } + out := new(CollectorSetList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CollectorSetList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CollectorSetPolicy) DeepCopyInto(out *CollectorSetPolicy) { + *out = *in + if in.DistibutionStrategy != nil { + in, out := &in.DistibutionStrategy, &out.DistibutionStrategy + *out = new(distributor.Type) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectorSetPolicy. +func (in *CollectorSetPolicy) DeepCopy() *CollectorSetPolicy { + if in == nil { + return nil + } + out := new(CollectorSetPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CollectorSetSpec) DeepCopyInto(out *CollectorSetSpec) { + *out = *in + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + in.CollectorStatefulSetSpec.DeepCopyInto(&out.CollectorStatefulSetSpec) + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } + if in.Policy != nil { + in, out := &in.Policy, &out.Policy + *out = new(CollectorSetPolicy) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectorSetSpec. +func (in *CollectorSetSpec) DeepCopy() *CollectorSetSpec { + if in == nil { + return nil + } + out := new(CollectorSetSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CollectorSetStatus) DeepCopyInto(out *CollectorSetStatus) { + *out = *in + if in.IDs != nil { + in, out := &in.IDs, &out.IDs + *out = make([]int32, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CollectorSetStatus. +func (in *CollectorSetStatus) DeepCopy() *CollectorSetStatus { + if in == nil { + return nil + } + out := new(CollectorSetStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/client/client.go b/pkg/client/client.go index e77974fb..516a259d 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -1,13 +1,15 @@ package client import ( + "encoding/json" "fmt" "reflect" "time" - crv1alpha1 "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" - apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + crv1alpha2 "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/serializer" @@ -17,7 +19,7 @@ import ( "k8s.io/client-go/rest" ) -const crdName = crv1alpha1.CollectorSetResourcePlural + "." + crv1alpha1.GroupName +const crdName = crv1alpha2.CollectorSetResourcePlural + "." + crv1alpha2.GroupName // Client represents the CollectorSet client. type Client struct { @@ -29,7 +31,7 @@ type Client struct { // NewForConfig instantiates and returns the client and scheme. func NewForConfig(cfg *rest.Config) (*Client, *runtime.Scheme, error) { s := runtime.NewScheme() - err := crv1alpha1.AddToScheme(s) + err := crv1alpha2.AddToScheme(s) if err != nil { return nil, nil, err } @@ -40,7 +42,7 @@ func NewForConfig(cfg *rest.Config) (*Client, *runtime.Scheme, error) { } config := *cfg - config.GroupVersion = &crv1alpha1.SchemeGroupVersion + config.GroupVersion = &crv1alpha2.SchemaGroupVersion config.APIPath = "/apis" config.ContentType = runtime.ContentTypeJSON config.NegotiatedSerializer = serializer.NewCodecFactory(s) @@ -64,41 +66,213 @@ func NewForConfig(cfg *rest.Config) (*Client, *runtime.Scheme, error) { return c, s, nil } +func getCustomResourceDefinationSchema() *apiextensionsv1.JSONSchemaProps { + minValue := 0.0 + minReplicas := 1.0 + minGroupID := -1.0 + defaultReplicas, _ := json.Marshal(1) //nolint:gosec + + return &apiextensionsv1.JSONSchemaProps{ + Description: "The collectorset specefication schema", + Type: "object", + Required: []string{"spec"}, + Properties: map[string]apiextensionsv1.JSONSchemaProps{ + "spec": { + Type: "object", + Required: []string{"imageRepository", "imageTag", "imagePullPolicy", "replicas", "size", "clusterName"}, + Properties: map[string]apiextensionsv1.JSONSchemaProps{ + "imageRepository": { + Description: "The image repository of the collector container", + Type: "string", + Default: &apiextensionsv1.JSON{ + Raw: []byte("\"logicmonitor/collector\""), + }, + }, + "imageTag": { + Description: "The image tag of the collector container", + Type: "string", + Default: &apiextensionsv1.JSON{ + Raw: []byte("\"latest\""), + }, + }, + "imagePullPolicy": { + Description: "The image pull policy of the collector container", + Type: "string", + Default: &apiextensionsv1.JSON{ + Raw: []byte("\"Always\""), + }, + Enum: []apiextensionsv1.JSON{ + { + Raw: []byte("\"Always\""), + }, + { + Raw: []byte("\"IfNotPresent\""), + }, + { + Raw: []byte("\"Never\""), + }, + }, + }, + "replicas": { + Description: "The number of collector replicas", + Type: "integer", + Minimum: &minReplicas, + Default: &apiextensionsv1.JSON{ + Raw: defaultReplicas, + }, + }, + "size": { + Description: "The collector size. Available collector sizes: nano, small, medium, large, extra_large, double_extra_large", + Type: "string", + Default: &apiextensionsv1.JSON{ + Raw: []byte("\"nano\""), + }, + Enum: []apiextensionsv1.JSON{ + { + Raw: []byte("\"nano\""), + }, + { + Raw: []byte("\"small\""), + }, + { + Raw: []byte("\"medium\""), + }, + { + Raw: []byte("\"large\""), + }, + { + Raw: []byte("\"extra_large\""), + }, + { + Raw: []byte("\"double_extra_large\""), + }, + }, + }, + "clusterName": { + Description: "The clustername of the collector", + Type: "string", + }, + "groupID": { + Description: "The groupId of the collector", + Type: "integer", + Minimum: &minGroupID, + }, + "escalationChainID": { + Description: "The escalation chain Id of the collectors", + Type: "integer", + Minimum: &minValue, + }, + "collectorVersion": { + Description: "The collector version (Fractional numbered version is invalid. For ex: 29.101 is invalid, correct input is 29101)", + Type: "integer", + Minimum: &minValue, + }, + "useEA": { + Description: "Flag to opt for EA collector versions", + Type: "boolean", + }, + "proxyURL": { + Description: "The Http/Https proxy url of the collector", + Type: "string", + }, + "secretName": { + Description: "The Secret resource name of the collector", + Type: "string", + }, + "statefulsetspec": { + Description: "The collector StatefulSet specification for customizations", + Type: "object", + }, + "policy": { + Type: "object", + Properties: map[string]apiextensionsv1.JSONSchemaProps{ + "distributionStrategy": { + Description: "Distribution strategy to provide collector ID to the client requests from available running collectors", + Type: "string", + Default: &apiextensionsv1.JSON{ + Raw: []byte("\"RoundRobin\""), + }, + }, + "orchestrator": { + Description: "The container orchestration platform designed to automate the deployment, scaling, and management of containerized applications", + Type: "string", + Default: &apiextensionsv1.JSON{ + Raw: []byte("\"Kubernetes\""), + }, + }, + }, + }, + }, + }, + }, + } +} + // CreateCustomResourceDefinition creates the CRD for collectors. -func (c *Client) CreateCustomResourceDefinition() (*apiextensionsv1beta1.CustomResourceDefinition, error) { - crd := &apiextensionsv1beta1.CustomResourceDefinition{ +// nolint: gocyclo +func (c *Client) CreateCustomResourceDefinition() (*apiextensionsv1.CustomResourceDefinition, error) { + schema := &apiextensionsv1.CustomResourceValidation{} + preserveUnknownFields := true + schema.OpenAPIV3Schema = getCustomResourceDefinationSchema() + crd := &apiextensionsv1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{ Name: crdName, }, - Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{ - Group: crv1alpha1.GroupName, - Version: crv1alpha1.SchemeGroupVersion.Version, - Scope: apiextensionsv1beta1.NamespaceScoped, - Names: apiextensionsv1beta1.CustomResourceDefinitionNames{ - Plural: crv1alpha1.CollectorSetResourcePlural, - Kind: reflect.TypeOf(crv1alpha1.CollectorSet{}).Name(), + Spec: apiextensionsv1.CustomResourceDefinitionSpec{ + Group: crv1alpha2.GroupName, + Names: apiextensionsv1.CustomResourceDefinitionNames{ + Plural: crv1alpha2.CollectorSetResourcePlural, + Kind: reflect.TypeOf(crv1alpha2.CollectorSet{}).Name(), + }, + Scope: apiextensionsv1.NamespaceScoped, + Versions: []apiextensionsv1.CustomResourceDefinitionVersion{ + { + Name: "v1alpha1", + Served: true, + Storage: false, + Schema: &apiextensionsv1.CustomResourceValidation{ + OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{ + Description: "The collectorset specification schema", + Type: "object", + XPreserveUnknownFields: &preserveUnknownFields, + }, + }, + }, + { + Name: "v1alpha2", + Served: true, + Storage: true, + Schema: schema, + }, }, }, } - _, err := c.APIExtensionsClientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + + _, err := c.APIExtensionsClientset.ApiextensionsV1().CustomResourceDefinitions().Create(crd) if err != nil { - return nil, err + if apierrors.IsAlreadyExists(err) { + if err1 := c.updateCRD(crd); err1 != nil { + return nil, err1 + } + return nil, nil + } + return nil, fmt.Errorf("error while creating crd: %w", err) } // wait for CRD being established err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) { - crd, err = c.APIExtensionsClientset.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crdName, metav1.GetOptions{}) + crd, err = c.APIExtensionsClientset.ApiextensionsV1().CustomResourceDefinitions().Get(crdName, metav1.GetOptions{}) if err != nil { return false, err } for _, cond := range crd.Status.Conditions { switch cond.Type { - case apiextensionsv1beta1.Established: - if cond.Status == apiextensionsv1beta1.ConditionTrue { + case apiextensionsv1.Established: + if cond.Status == apiextensionsv1.ConditionTrue { return true, err } - case apiextensionsv1beta1.NamesAccepted: - if cond.Status == apiextensionsv1beta1.ConditionFalse { + case apiextensionsv1.NamesAccepted: + if cond.Status == apiextensionsv1.ConditionFalse { fmt.Printf("Name conflict: %v\n", cond.Reason) } } @@ -106,7 +280,7 @@ func (c *Client) CreateCustomResourceDefinition() (*apiextensionsv1beta1.CustomR return false, err }) if err != nil { - deleteErr := c.APIExtensionsClientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(crdName, nil) + deleteErr := c.APIExtensionsClientset.ApiextensionsV1().CustomResourceDefinitions().Delete(crdName, nil) if deleteErr != nil { return nil, errors.NewAggregate([]error{err, deleteErr}) } @@ -116,20 +290,18 @@ func (c *Client) CreateCustomResourceDefinition() (*apiextensionsv1beta1.CustomR return crd, nil } -// // WaitForCollectorMonitoring creates a collector and waits for it to be ready. -// func WaitForCollectorMonitoring(clientset *rest.RESTClient, name string) error { -// return wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) { -// var collector crv1alpha1.CollectorSet -// err := clientset.Get(). -// Resource(crv1alpha1.CollectorSetResourcePlural). -// Namespace(apiv1.NamespaceDefault). -// Name(name). -// Do().Into(&collector) - -// if err == nil && collector.Status.State == crv1alpha1.CollectorSetStateMonitoring { -// return true, nil -// } - -// return false, err -// }) -// } +func (c *Client) updateCRD(crd *apiextensionsv1.CustomResourceDefinition) error { + // Get current CRD object for retrieving ResourceVersion + // ResourceVersion is required for updating newer CRD object + existingCrd, err := c.APIExtensionsClientset.ApiextensionsV1().CustomResourceDefinitions().Get(crdName, metav1.GetOptions{}) + if err != nil { + return fmt.Errorf("error while retrieving existing crd: %w", err) + } + + crd.SetResourceVersion(existingCrd.GetResourceVersion()) + _, err1 := c.APIExtensionsClientset.ApiextensionsV1().CustomResourceDefinitions().Update(crd) + if err1 != nil { + return fmt.Errorf("error while updating crd: %w", err1) + } + return nil +} diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index b2a068dc..f5dd6265 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -4,10 +4,8 @@ import ( apiv1 "k8s.io/api/core/v1" ) -var ( - // Version is the Argus version and is set at build time. - Version string -) +// Version is the Argus version and is set at build time. +var Version string const ( // UserAgentBase is the base string for the User-Agent HTTP header. diff --git a/pkg/controller/collectorset.go b/pkg/controller/collectorset.go index 257bce96..559ad1b3 100644 --- a/pkg/controller/collectorset.go +++ b/pkg/controller/collectorset.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - crv1alpha1 "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" + crv1alpha2 "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" "github.com/logicmonitor/k8s-collectorset-controller/pkg/constants" "github.com/logicmonitor/lm-sdk-go/client" "github.com/logicmonitor/lm-sdk-go/client/lm" @@ -12,7 +12,6 @@ import ( log "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" apiv1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -22,7 +21,7 @@ import ( // CreateOrUpdateCollectorSet creates a replicaset for each collector in // a CollectorSet -func CreateOrUpdateCollectorSet(collectorset *crv1alpha1.CollectorSet, controller *Controller) ([]int32, error) { +func CreateOrUpdateCollectorSet(collectorset *crv1alpha2.CollectorSet, controller *Controller) ([]int32, error) { groupID := collectorset.Spec.GroupID if groupID == 0 || !checkCollectorGroupExistsByID(controller.LogicmonitorClient, groupID) { groupName := constants.ClusterCollectorGroupPrefix + collectorset.Spec.ClusterName @@ -66,8 +65,7 @@ func CreateOrUpdateCollectorSet(collectorset *crv1alpha1.CollectorSet, controlle return collectorset.Status.IDs, nil } -func createStsObject(collectorset *crv1alpha1.CollectorSet, ids []int32, ignoreSSL bool) (*appsv1.StatefulSet, error) { - +func createStsObject(collectorset *crv1alpha2.CollectorSet, ids []int32, ignoreSSL bool) (*appsv1.StatefulSet, error) { secretIsOptional := false collectorSize := strings.ToLower(collectorset.Spec.Size) log.Infof("Collector size is %s", collectorSize) @@ -190,11 +188,11 @@ func createStsObject(collectorset *crv1alpha1.CollectorSet, ids []int32, ignoreS }, { Name: "collector_version", - Value: fmt.Sprint(collectorset.Spec.CollectorVersion), //the default value is 0, santaba will assign the latest version + Value: fmt.Sprint(collectorset.Spec.CollectorVersion), // the default value is 0, santaba will assign the latest version }, { Name: "use_ea", - Value: fmt.Sprint(collectorset.Spec.UseEA), //the default value is false, santaba will assign the latest GD version + Value: fmt.Sprint(collectorset.Spec.UseEA), // the default value is false, santaba will assign the latest GD version }, { Name: "COLLECTOR_IDS", @@ -202,7 +200,7 @@ func createStsObject(collectorset *crv1alpha1.CollectorSet, ids []int32, ignoreS }, { Name: "ignore_ssl", - Value: fmt.Sprint(ignoreSSL), //the default value is false + Value: fmt.Sprint(ignoreSSL), // the default value is false }, }, Resources: getResourceRequirements(collectorSize), @@ -217,7 +215,7 @@ func createStsObject(collectorset *crv1alpha1.CollectorSet, ids []int32, ignoreS return &statefulset, nil } -func getCollectorImage(collectorset *crv1alpha1.CollectorSet) string { +func getCollectorImage(collectorset *crv1alpha2.CollectorSet) string { if collectorset.Spec.ImageRepository == "" { return constants.DefaultCollectorImage } @@ -228,7 +226,7 @@ func getCollectorImage(collectorset *crv1alpha1.CollectorSet) string { return collectorset.Spec.ImageRepository + ":" + imageTag } -func getCollectorImagePullPolicy(collectorset *crv1alpha1.CollectorSet) (apiv1.PullPolicy, error) { +func getCollectorImagePullPolicy(collectorset *crv1alpha2.CollectorSet) (apiv1.PullPolicy, error) { if collectorset.Spec.ImagePullPolicy == "" { return constants.DefaultCollectorImagePullPolicy, nil } @@ -237,10 +235,9 @@ func getCollectorImagePullPolicy(collectorset *crv1alpha1.CollectorSet) (apiv1.P return collectorset.Spec.ImagePullPolicy, nil } return "", fmt.Errorf("unsupported imagePullPolicy value: %v, supported values: [%v, %v, %v]", collectorset.Spec.ImagePullPolicy, apiv1.PullAlways, apiv1.PullNever, apiv1.PullIfNotPresent) - } -func setProxyConfiguration(collectorset *crv1alpha1.CollectorSet, statefulset *appsv1.StatefulSet) { +func setProxyConfiguration(collectorset *crv1alpha2.CollectorSet, statefulset *appsv1.StatefulSet) { if collectorset.Spec.ProxyURL == "" { return } @@ -282,17 +279,17 @@ func setProxyConfiguration(collectorset *crv1alpha1.CollectorSet, statefulset *a } } -func validateTolerations(tolerations []v1.Toleration) { +func validateTolerations(tolerations []apiv1.Toleration) { valid := true if tolerations != nil { for _, toleration := range tolerations { - if toleration.Operator == v1.TolerationOpExists && toleration.Value != "" { + if toleration.Operator == apiv1.TolerationOpExists && toleration.Value != "" { log.Errorf("Value must be empty when 'operator' is 'Exists'. Toleration: %v", toleration) valid = false - } else if toleration.Operator != v1.TolerationOpExists && toleration.Key == "" { + } else if toleration.Operator != apiv1.TolerationOpExists && toleration.Key == "" { log.Errorf("Operator must be 'Exists' when 'key' is empty. Toleration: %v", toleration) valid = false - } else if toleration.Effect != v1.TaintEffectNoExecute && toleration.TolerationSeconds != nil { + } else if toleration.Effect != apiv1.TaintEffectNoExecute && toleration.TolerationSeconds != nil { log.Errorf("Effect must be 'NoExecute' when 'tolerationSeconds' is set. Toleration: %v", toleration) valid = false } @@ -410,7 +407,7 @@ func updateCollectors(client *client.LMSdkGo, ids []int32) error { } // DeleteCollectorSet deletes the collectorset. -func DeleteCollectorSet(collectorset *crv1alpha1.CollectorSet, client clientset.Interface) error { +func DeleteCollectorSet(collectorset *crv1alpha2.CollectorSet, client clientset.Interface) error { data := []byte(`[{"op":"add","path":"/spec/replicas","value": 0}]`) if _, err := client.AppsV1().StatefulSets(collectorset.Namespace).Patch(collectorset.Name, types.JSONPatchType, data); err != nil { return err @@ -433,7 +430,7 @@ func checkCollectorGroupExistsByID(client *client.LMSdkGo, id int32) bool { return true } -func getCollectorGroupID(client *client.LMSdkGo, name string, collectorset *crv1alpha1.CollectorSet) (int32, error) { +func getCollectorGroupID(client *client.LMSdkGo, name string, collectorset *crv1alpha2.CollectorSet) (int32, error) { params := lm.NewGetCollectorGroupListParams() filter := fmt.Sprintf("name:\"%s\"", name) params.SetFilter(&filter) @@ -452,8 +449,7 @@ func getCollectorGroupID(client *client.LMSdkGo, name string, collectorset *crv1 return -1, fmt.Errorf("failed to get collector group ID") } -func addCollectorGroup(client *client.LMSdkGo, name string, collectorset *crv1alpha1.CollectorSet) (int32, error) { - +func addCollectorGroup(client *client.LMSdkGo, name string, collectorset *crv1alpha2.CollectorSet) (int32, error) { kubernetesLabelApp := constants.CustomPropertyKubernetesLabelApp kubernetesLabelAppValue := constants.CustomPropertyKubernetesLabelAppValue autoClusterName := constants.CustomPropertyAutoClusterName @@ -477,7 +473,7 @@ func addCollectorGroup(client *client.LMSdkGo, name string, collectorset *crv1al } // $(statefulset name)-$(ordinal) -func getCollectorIDs(client *client.LMSdkGo, groupID int32, collectorset *crv1alpha1.CollectorSet) ([]int32, error) { +func getCollectorIDs(client *client.LMSdkGo, groupID int32, collectorset *crv1alpha2.CollectorSet) ([]int32, error) { var ids []int32 for ordinal := int32(0); ordinal < *collectorset.Spec.Replicas; ordinal++ { name := fmt.Sprintf("%s%s-%d", constants.ClusterCollectorGroupPrefix, collectorset.Spec.ClusterName, ordinal) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index d19bed85..1f3eba8e 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - crv1alpha1 "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha1" + crv1alpha2 "github.com/logicmonitor/k8s-collectorset-controller/pkg/apis/v1alpha2" collectorsetclient "github.com/logicmonitor/k8s-collectorset-controller/pkg/client" "github.com/logicmonitor/k8s-collectorset-controller/pkg/config" "github.com/logicmonitor/k8s-collectorset-controller/pkg/distributor" @@ -77,8 +77,8 @@ func (c *Controller) Run(ctx context.Context) error { func (c *Controller) watch(ctx context.Context) error { _, controller := cache.NewInformer( - cache.NewListWatchFromClient(c.RESTClient, crv1alpha1.CollectorSetResourcePlural, apiv1.NamespaceAll, fields.Everything()), - &crv1alpha1.CollectorSet{}, + cache.NewListWatchFromClient(c.RESTClient, crv1alpha2.CollectorSetResourcePlural, apiv1.NamespaceAll, fields.Everything()), + &crv1alpha2.CollectorSet{}, 0, cache.ResourceEventHandlerFuncs{ AddFunc: c.addFunc, @@ -92,7 +92,7 @@ func (c *Controller) watch(ctx context.Context) error { } func (c *Controller) addFunc(obj interface{}) { - collectorset := obj.(*crv1alpha1.CollectorSet) + collectorset := obj.(*crv1alpha2.CollectorSet) log.Infof("Starting to create collectorset: %s", collectorset.Name) ids, err := CreateOrUpdateCollectorSet(collectorset, c) @@ -126,8 +126,8 @@ func (c *Controller) addFunc(obj interface{}) { // TODO: updating the collectorset ids in the add func will trigger this. We // need to check for this case func (c *Controller) updateFunc(oldObj, newObj interface{}) { - _ = oldObj.(*crv1alpha1.CollectorSet) - newcollectorset := newObj.(*crv1alpha1.CollectorSet) + _ = oldObj.(*crv1alpha2.CollectorSet) + newcollectorset := newObj.(*crv1alpha2.CollectorSet) log.Infof("Starting to update collectorset: %s", newcollectorset.Name) _, err := CreateOrUpdateCollectorSet(newcollectorset, c) @@ -146,7 +146,7 @@ func (c *Controller) updateFunc(oldObj, newObj interface{}) { } func (c *Controller) deleteFunc(obj interface{}) { - collectorset := obj.(*crv1alpha1.CollectorSet) + collectorset := obj.(*crv1alpha2.CollectorSet) log.Infof("Starting to delete collectorset: %s", collectorset.Name) if err := DeleteCollectorSet(collectorset, c.Clientset); err != nil { @@ -161,34 +161,20 @@ func (c *Controller) deleteFunc(obj interface{}) { log.Infof("Finished deleting CollectorSet: %s", collectorset.Name) } -// func (c *Controller) listCollectorSets() (*crv1alpha1.CollectorSetList, error) { -// collectorsetList := &crv1alpha1.CollectorSetList{} -// err := c.RESTClient.Get(). -// Resource(crv1alpha1.CollectorSetResourcePlural). -// Do(). -// Into(collectorsetList) -// if err != nil { -// return nil, fmt.Errorf("Failed to get CollectorSet list: %v", err) -// } - -// return collectorsetList, nil -// } - -func (c *Controller) updateCollectorSetStatus(collectorset *crv1alpha1.CollectorSet, ids []int32) (*crv1alpha1.CollectorSet, error) { +func (c *Controller) updateCollectorSetStatus(collectorset *crv1alpha2.CollectorSet, ids []int32) (*crv1alpha2.CollectorSet, error) { collectorsetCopy := collectorset.DeepCopy() - collectorsetCopy.Status = crv1alpha1.CollectorSetStatus{ - State: crv1alpha1.CollectorSetStateRegistered, + collectorsetCopy.Status = crv1alpha2.CollectorSetStatus{ + State: crv1alpha2.CollectorSetStateRegistered, IDs: ids, } err := c.RESTClient.Put(). Name(collectorset.ObjectMeta.Name). Namespace(collectorset.ObjectMeta.Namespace). - Resource(crv1alpha1.CollectorSetResourcePlural). + Resource(crv1alpha2.CollectorSetResourcePlural). Body(collectorsetCopy). Do(). Error() - if err != nil { return nil, fmt.Errorf("Failed to update status: %v", err) } @@ -238,7 +224,7 @@ func waitForCollectorsToRegister(lmClient *client.LMSdkGo, ids []int32) error { } } -func (c *Controller) save(collectorset *crv1alpha1.CollectorSet) error { +func (c *Controller) save(collectorset *crv1alpha2.CollectorSet) error { p := &policy.Policy{} switch *collectorset.Spec.Policy.DistibutionStrategy { @@ -260,6 +246,6 @@ func (c *Controller) save(collectorset *crv1alpha1.CollectorSet) error { return nil } -func (c *Controller) remove(collectorset *crv1alpha1.CollectorSet) error { +func (c *Controller) remove(collectorset *crv1alpha2.CollectorSet) error { return c.Storage.DeletePolicy(collectorset.Name) } diff --git a/pkg/controller/logicmonitor.go b/pkg/controller/logicmonitor.go index 9ac60547..231fa11f 100644 --- a/pkg/controller/logicmonitor.go +++ b/pkg/controller/logicmonitor.go @@ -19,7 +19,7 @@ func newLMClient(collectorsetconfig *config.Config) (*client.LMSdkGo, error) { domain := collectorsetconfig.Account + ".logicmonitor.com" config.SetAccountDomain(&domain) if collectorsetconfig.ProxyURL == "" { - //return client.New(config), nil + // return client.New(config), nil if collectorsetconfig.IgnoreSSL { return newLMClientWithoutSSL(config) } @@ -56,10 +56,8 @@ func newClientWithProxy(config *client.Config, collectorsetconfig *config.Config } func newLMClientWithoutSSL(config *client.Config) (*client.LMSdkGo, error) { - - var opts = httptransport.TLSClientOptions{InsecureSkipVerify: true} - var httpClient, err = httptransport.TLSClient(opts) - + opts := httptransport.TLSClientOptions{InsecureSkipVerify: true} + httpClient, err := httptransport.TLSClient(opts) if err != nil { return nil, err } diff --git a/proto/api.proto b/proto/api.proto index 6477b1b8..395854d6 100644 --- a/proto/api.proto +++ b/proto/api.proto @@ -1,5 +1,7 @@ syntax = "proto3"; +option go_package = "github.com/logicmonitor/k8s-collectorset-controller/api"; + package api; // The collectorset service definition.