Skip to content

Commit

Permalink
merge resourcedistribution generator mods and makefiles (#70)
Browse files Browse the repository at this point in the history
Signed-off-by: dong <dong4325@126.com>

Signed-off-by: dong <dong4325@126.com>
  • Loading branch information
dong4325 authored Oct 13, 2022
1 parent aa23984 commit a27ae8c
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 556 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ jobs:
asset_path: ./_bin/kubectl-kruise/kubectl-kruise-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
asset_name: kubectl-kruise-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
asset_content_type: binary/octet-stream
- name: Build resourcedistribution-generator
run: |
${{ env.GO_BUILD_ENV }} GOOS=${{ steps.get_matrix.outputs.OS }} GOARCH=${{ steps.get_matrix.outputs.ARCH }} \
go build -ldflags "${{ env.LDFLAGS }}" \
-o _bin/resourcedistribution-generator/${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}/resourcedistributiongenerator -v \
./cmd/resourcedistributiongenerator/main.go
- name: Compress resourcedistribution-generator
run: |
cd _bin/resourcedistribution-generator && \
${{ env.DIST_DIRS }} tar -zcf resourcedistribution-generator-{}.tar.gz {} \; && \
cd .. && \
sha256sum resourcedistribution-generator/resourcedistribution-generator-* >> sha256-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.txt \
- name: Upload resourcedistribution-generator tar.gz
uses: actions/upload-release-asset@v1.0.2
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./_bin/resourcedistribution-generator/resourcedistribution-generator-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
asset_name: resourcedistribution-generator-${{ steps.get_matrix.outputs.OS }}-${{ steps.get_matrix.outputs.ARCH }}.tar.gz
asset_content_type: binary/octet-stream
- name: Post sha256
uses: actions/upload-artifact@v2
with:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ LDFLAGS = $(shell ./version.sh)

default: build

build: kubectl-kruise
build: kubectl-kruise resource-distribution-generator

kubectl-kruise: fmt vet
GO111MODULE=on CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o bin/kubectl-kruise cmd/plugin/main.go

resource-distribution-generator: fmt vet
GO111MODULE=on CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o bin/resourcedistributiongenerator cmd/resourcedistributiongenerator/main.go

test:
find . -iname '*.go' -type f | grep -v /vendor/ | xargs gofmt -l
GO111MODULE=on go test -v -race ./...
Expand Down
20 changes: 0 additions & 20 deletions cmd/resourcedistributiongenerator/Makefile

This file was deleted.

218 changes: 0 additions & 218 deletions cmd/resourcedistributiongenerator/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2022 The Kruise Authors.
Copyright 2015 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.
Expand Down Expand Up @@ -34,13 +35,17 @@ type ResourceDistributionPlugin struct {

// Options for the resourcedistribution.
// GeneratorOptions same as configmap and secret generator Options
//
// The features of fields DisableNameSuffixHash and Immutable in Options are not implemented yet
Options *types.GeneratorOptions `json:"options,omitempty" yaml:"options,omitempty"`

// Behavior of generated resource, must be one of:
// 'create': create a new one
// 'replace': replace the existing one
// 'merge': merge with the existing one
Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"`
//
// The feature of this field is not implemented yet
//Behavior string `json:"behavior,omitempty" yaml:"behavior,omitempty"`
}

// ResourceArgs contain arguments for the resource to be distributed.
Expand All @@ -56,6 +61,8 @@ type ResourceArgs struct {

// Options for the resource to be distributed.
// GeneratorOptions same as configmap and secret generator Options
//
// The feature of field DisableNameSuffixHash in ResourceOptions is not implemented yet
ResourceOptions *types.GeneratorOptions `json:"resourceOptions,omitempty" yaml:"resourceOptions,omitempty"`

// Type of the secret. It can be "Opaque" (default), or "kubernetes.io/tls".
Expand All @@ -77,7 +84,42 @@ type TargetsArgs struct {
IncludedNamespaces []string `json:"includedNamespaces,omitempty" yaml:"includedNamespaces,omitempty"`

// NamespaceLabelSelector for the generator.
NamespaceLabelSelector *metav1.LabelSelector `json:"namespaceLabelSelector,omitempty" yaml:"namespaceLabelSelector,omitempty"`
NamespaceLabelSelector *LabelSelector `json:"namespaceLabelSelector,omitempty" yaml:"namespaceLabelSelector,omitempty"`
}

// It is the same as metav1.LabelSelector except that the YAMl tag is added after each field
//
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +structType=atomic
type LabelSelector struct {
// matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
// map is equivalent to an element of matchExpressions, whose key field is "key", the
// operator is "In", and the values array contains only "value". The requirements are ANDed.
// +optional
MatchLabels map[string]string `json:"matchLabels,omitempty" protobuf:"bytes,1,rep,name=matchLabels" yaml:"matchLabels,omitempty"`
// matchExpressions is a list of label selector requirements. The requirements are ANDed.
// +optional
MatchExpressions []LabelSelectorRequirement `json:"matchExpressions,omitempty" protobuf:"bytes,2,rep,name=matchExpressions" yaml:"matchExpressions,omitempty"`
}

// A label selector requirement is a selector that contains values, a key, and an operator that
// relates the key and values.
type LabelSelectorRequirement struct {
// key is the label key that the selector applies to.
// +patchMergeKey=key
// +patchStrategy=merge
Key string `json:"key" patchStrategy:"merge" patchMergeKey:"key" protobuf:"bytes,1,opt,name=key" yaml:"key,omitempty"`
// operator represents a key's relationship to a set of values.
// Valid operators are In, NotIn, Exists and DoesNotExist.
Operator metav1.LabelSelectorOperator `json:"operator" protobuf:"bytes,2,opt,name=operator,casttype=LabelSelectorOperator" yaml:"operator,omitempty"`
// values is an array of string values. If the operator is In or NotIn,
// the values array must be non-empty. If the operator is Exists or DoesNotExist,
// the values array must be empty. This array is replaced during a strategic
// merge patch.
// +optional
Values []string `json:"values,omitempty" protobuf:"bytes,3,rep,name=values" yaml:"values,omitempty"`
}

func BuildCmd() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/resourcedistributiongenerator/generator/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func setAllNs(rn *yaml.RNode, allNs bool) error {
return nil
}

func setNsLabelSelector(rn *yaml.RNode, sel *metav1.LabelSelector) error {
func setNsLabelSelector(rn *yaml.RNode, sel *LabelSelector) error {
if sel == nil {
return nil
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func setMatchLabels(rn *yaml.RNode, matchLabels map[string]string) error {
return nil
}

func setMatchExpressions(rn *yaml.RNode, args []metav1.LabelSelectorRequirement) error {
func setMatchExpressions(rn *yaml.RNode, args []LabelSelectorRequirement) error {
if args == nil {
return nil
}
Expand Down
15 changes: 0 additions & 15 deletions cmd/resourcedistributiongenerator/go.mod

This file was deleted.

Loading

0 comments on commit a27ae8c

Please sign in to comment.