diff --git a/apis/v1alpha1/groupversion_info.go b/apis/v1alpha1/groupversion_info.go index 0726d72..c731048 100644 --- a/apis/v1alpha1/groupversion_info.go +++ b/apis/v1alpha1/groupversion_info.go @@ -15,8 +15,8 @@ limitations under the License. */ // Package v1alpha1 contains API Schema definitions for the game.kruise.io v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=game.kruise.io +// +kubebuilder:object:generate=true +// +groupName=game.kruise.io package v1alpha1 import ( diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 8ca8c4a..4d72aed 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -36,14 +36,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 494b657..1624d9c 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -36,14 +36,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/externalscaler/externalscaler.go b/pkg/externalscaler/externalscaler.go index 79ed0c1..f79096d 100644 --- a/pkg/externalscaler/externalscaler.go +++ b/pkg/externalscaler/externalscaler.go @@ -17,23 +17,23 @@ func (e *ExternalScaler) mustEmbedUnimplementedExternalScalerServer() { } func (e *ExternalScaler) IsActive(ctx context.Context, scaledObjectRef *ScaledObjectRef) (*IsActiveResponse, error) { - name := scaledObjectRef.GetName() - ns := scaledObjectRef.GetNamespace() - gss := &gamekruiseiov1alpha1.GameServerSet{} - err := e.client.Get(ctx, types.NamespacedName{Namespace: ns, Name: name}, gss) - if err != nil { - klog.Error(err) - return nil, err - } - currentReplicas := gss.Status.CurrentReplicas - numWaitToBeDeleted := gss.Status.WaitToBeDeletedReplicas - if numWaitToBeDeleted == nil { - return nil, fmt.Errorf("GameServerSet %s/%s has not inited", ns, name) - } - desireReplicas := currentReplicas - *numWaitToBeDeleted - return &IsActiveResponse{ - Result: desireReplicas > 0, - }, nil + name := scaledObjectRef.GetName() + ns := scaledObjectRef.GetNamespace() + gss := &gamekruiseiov1alpha1.GameServerSet{} + err := e.client.Get(ctx, types.NamespacedName{Namespace: ns, Name: name}, gss) + if err != nil { + klog.Error(err) + return nil, err + } + currentReplicas := gss.Status.CurrentReplicas + numWaitToBeDeleted := gss.Status.WaitToBeDeletedReplicas + if numWaitToBeDeleted == nil { + return nil, fmt.Errorf("GameServerSet %s/%s has not inited", ns, name) + } + desireReplicas := currentReplicas - *numWaitToBeDeleted + return &IsActiveResponse{ + Result: desireReplicas > 0, + }, nil } func (e *ExternalScaler) StreamIsActive(scaledObject *ScaledObjectRef, epsServer ExternalScaler_StreamIsActiveServer) error { diff --git a/pkg/webhook/util/writer/atomic/atomic_writer.go b/pkg/webhook/util/writer/atomic/atomic_writer.go index 0ca2520..b2387f7 100644 --- a/pkg/webhook/util/writer/atomic/atomic_writer.go +++ b/pkg/webhook/util/writer/atomic/atomic_writer.go @@ -42,9 +42,9 @@ const ( // // Note: // -// 1. Writer reserves the set of pathnames starting with `..`. -// 2. Writer offers no concurrency guarantees and must be synchronized -// by the caller. +// 1. Writer reserves the set of pathnames starting with `..`. +// 2. Writer offers no concurrency guarantees and must be synchronized +// by the caller. // // The visible files in this volume are symlinks to files in the writer's data // directory. Actual files are stored in a hidden timestamped directory which @@ -86,33 +86,37 @@ const ( // // The Write algorithm is: // -// 1. The payload is validated; if the payload is invalid, the function returns -// 2.  The current timestamped directory is detected by reading the data directory -// symlink -// 3. The old version of the volume is walked to determine whether any -// portion of the payload was deleted and is still present on disk. -// 4. The data in the current timestamped directory is compared to the projected -// data to determine if an update is required. -// 5.  A new timestamped dir is created -// 6. The payload is written to the new timestamped directory -// 7.  Symlinks and directory for new user-visible files are created (if needed). +// 1. The payload is validated; if the payload is invalid, the function returns +// 2.  The current timestamped directory is detected by reading the data directory +// symlink // -// For example, consider the files: -// /podName -// /user/labels -// /k8s/annotations +// 3. The old version of the volume is walked to determine whether any +// portion of the payload was deleted and is still present on disk. // -// The user visible files are symbolic links into the internal data directory: -// /podName -> ..data/podName -// /usr -> ..data/usr -// /k8s -> ..data/k8s +// 4. The data in the current timestamped directory is compared to the projected +// data to determine if an update is required. +// 5.  A new timestamped dir is created +// +// 6. The payload is written to the new timestamped directory +// 7.  Symlinks and directory for new user-visible files are created (if needed). +// +// For example, consider the files: +// /podName +// /user/labels +// /k8s/annotations +// +// The user visible files are symbolic links into the internal data directory: +// /podName -> ..data/podName +// /usr -> ..data/usr +// /k8s -> ..data/k8s +// +// The data directory itself is a link to a timestamped directory with +// the real data: +// /..data -> ..2016_02_01_15_04_05.12345678/ +// 8.  A symlink to the new timestamped directory ..data_tmp is created that will +// become the new data directory +// 9.  The new data directory symlink is renamed to the data directory; rename is atomic // -// The data directory itself is a link to a timestamped directory with -// the real data: -// /..data -> ..2016_02_01_15_04_05.12345678/ -// 8.  A symlink to the new timestamped directory ..data_tmp is created that will -// become the new data directory -// 9.  The new data directory symlink is renamed to the data directory; rename is atomic // 10. Old paths are removed from the user-visible portion of the target directory // 11.  The previous timestamped directory is removed, if it exists func (w *Writer) Write(payload map[string]FileProjection) error {