← Back to Pull requests

Add a kubectl command to delete the HNC configuration of a specific type #606

Merged
sophieliu15 merged 3 files (78 lines) on Apr 06, 2020 21:45 UTC
View on GitHub
sophieliu15 sophieliu15 commented on Apr 03, 2020 20:52 UTC
Author

This PR adds a kubectl command to delete the HNC configuration of a specific type.

Example usage: kubectl hns config delete-type --apiVersion v1 --kind Secret

Issue: #454

Diff: 78 lines (+78 / -0) across 3 files Reviewer: adrianludwin Review duration: 4373m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.55) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 78 lines diff across 3 files
0.55
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.261
Sensitive Paths sensitive_paths
0.055
Real PR Conversation Timeline
10 items
sophieliu15 sophieliu15 commented on Apr 03, 2020 20:53 UTC
Author

/assign @adrianludwin
/assign @yiqigao217
cc: @adrianchung

adrianludwin adrianludwin commented on code on Apr 03, 2020 21:01 UTC
Code Review
incubator/hnc/pkg/kubectl/configdelete.go:1
@@ -0,0 +1,61 @@
+/*
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package kubectl
+
+import (
+	"fmt"
+
+	"github.com/spf13/cobra"
+)
+
+var configDeleteCmd = &cobra.Command{
+	Use:   "delete-type --apiVersion X --kind Y",
+	Short: "Delete the HNC configuration of a specific type",
+	Example: fmt.Sprintf("  # Delete configuration of a core type\n" +
+		"  kubectl hns config delete-type --apiVersion v1 --kind Secret\n\n" +
+		"  # Delete configuration of a custom type\n" +
+		"  kubectl hns config delete-type --apiversion stable.example.com/v1 --kind CronTab"),
+	Run: func(cmd *cobra.Command, args []string) {
+		flags := cmd.Flags()
+		apiVersion, _ := flags.GetString("apiVersion")
+		kind, _ := flags.GetString("kind")
+		config := client.getHNCConfig()
+
+		i := 0
+		for _, t := range config.Spec.Types {
+			if t.APIVersion != apiVersion || t.Kind != kind {
+				config.Spec.Types[i] = t
+				i++
+			}
+		}

I feel like the more Go-idiomatic way of doing this would be:

newTypes := []api.Whatever{}
found := false
for _, t := range config.Spec.Types {
  if t.APIVersion == apiVersion && t.Kind == kind {
    found := true
  } else {
    newTypes = append(newTypes, t)
  }
}
if !found { ... error ... }
config.Spec.Types = newTypes

The current way has a "loop" variable that isn't really incremented all the time plus you're modifying a list as you step over it, which I'm pretty sure works fine but always makes me closely re-read it to make sure I'm not missing something important.

sophieliu15 sophieliu15 commented on code on Apr 06, 2020 15:31 UTC
Code Review
incubator/hnc/pkg/kubectl/configdelete.go:1
@@ -0,0 +1,61 @@
+/*
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package kubectl
+
+import (
+	"fmt"
+
+	"github.com/spf13/cobra"
+)
+
+var configDeleteCmd = &cobra.Command{
+	Use:   "delete-type --apiVersion X --kind Y",
+	Short: "Delete the HNC configuration of a specific type",
+	Example: fmt.Sprintf("  # Delete configuration of a core type\n" +
+		"  kubectl hns config delete-type --apiVersion v1 --kind Secret\n\n" +
+		"  # Delete configuration of a custom type\n" +
+		"  kubectl hns config delete-type --apiversion stable.example.com/v1 --kind CronTab"),
+	Run: func(cmd *cobra.Command, args []string) {
+		flags := cmd.Flags()
+		apiVersion, _ := flags.GetString("apiVersion")
+		kind, _ := flags.GetString("kind")
+		config := client.getHNCConfig()
+
+		i := 0
+		for _, t := range config.Spec.Types {
+			if t.APIVersion != apiVersion || t.Kind != kind {
+				config.Spec.Types[i] = t
+				i++
+			}
+		}

Thanks so much for the suggestion and explanation! Changed to more Go-idiomatic way.

adrianludwin adrianludwin commented on Apr 06, 2020 16:57 UTC
Reviewer

/approve
/lgtm
/hold
/assign @rjbez17

sophieliu15 sophieliu15 commented on Apr 06, 2020 19:14 UTC
Author

I changed the commit and PR message to refer to the correct issue (454 instead of 545).

rjbez17 rjbez17 commented on Apr 06, 2020 20:39 UTC
Contributor

/lgtm
/approve

@sophieliu15 does this need to merge after #595 ?

k8s-ci-robot k8s-ci-robot commented on Apr 06, 2020 20:40 UTC
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/606#pullrequestreview-388442293" title="LGTM">adrianludwin</a>, <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/606#issuecomment-610024711" title="Approved">rjbez17</a>, <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/606#" title="Author self-approved">sophieliu15</a>

The full list of commands accepted by this bot can be found here.

The pull request process is described here

<details >
Needs approval from an approver in each of these files:

  • ~~OWNERS~~ [adrianludwin,rjbez17]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    sophieliu15 sophieliu15 commented on Apr 06, 2020 21:33 UTC
    Author

    /lgtm

    /approve

    > @sophieliu15 does this need to merge after #595 ?

    Hi @rjbez17 ! No it doesn't need to be merged after #595. Both are independent.

    rjbez17 rjbez17 commented on Apr 06, 2020 21:39 UTC
    Contributor

    /hold cancel

    Reviewers
    Assignees
    sophieliu15 sophieliu15
    Labels
    risk: low confidence: 91.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 55.2% (MEDIUM) · Higher = larger blast radius
    55.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.7% · Lower = rushed or shallow review
    91.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.6% · Safe to merge
    4.6%