Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staged policy changes in Calicoctl #9943

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion calicoctl/calicoctl/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy,
StagedKubernetesNetworkPolicy, NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
--context=<context> The name of the kubeconfig context to use.
--allow-version-mismatch Allow client and cluster versions mismatch.
Expand Down
3 changes: 2 additions & 1 deletion calicoctl/calicoctl/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy,
StagedKubernetesNetworkPolicy, NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
--context=<context> The name of the kubeconfig context to use.
--allow-version-mismatch Allow client and cluster versions mismatch.
Expand Down
4 changes: 2 additions & 2 deletions calicoctl/calicoctl/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy and WorkloadEndpoint.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy,
StagedKubernetesNetworkPolicy, NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
--context=<context> The name of the kubeconfig context to use.
--allow-version-mismatch Allow client and cluster versions mismatch.
Expand Down
3 changes: 2 additions & 1 deletion calicoctl/calicoctl/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy, StagedKubernetesNetworkPolicy,
NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
-A --all-namespaces If present, list the requested object(s) across all namespaces.
--export If present, returns the requested object(s) stripped of
Expand Down
3 changes: 2 additions & 1 deletion calicoctl/calicoctl/commands/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy, StagedKubernetesNetworkPolicy,
NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
--overwrite If true, overwrite the value when the key is already
present in labels. Otherwise reports error when the
Expand Down
3 changes: 2 additions & 1 deletion calicoctl/calicoctl/commands/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy,
StagedKubernetesNetworkPolicy, NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
--context=<context> The name of the kubeconfig context to use.
--allow-version-mismatch Allow client and cluster versions mismatch.
Expand Down
3 changes: 2 additions & 1 deletion calicoctl/calicoctl/commands/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Options:
configuration in YAML or JSON format.
[default: ` + constants.DefaultConfigPath + `]
-n --namespace=<NS> Namespace of the resource.
Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
Only applicable to NetworkPolicy, StagedNetworkPolicy,
StagedKubernetesNetworkPolicy, NetworkSet, and WorkloadEndpoint.
Uses the default namespace if not specified.
--context=<context> The name of the kubeconfig context to use.
--allow-version-mismatch Allow client and cluster versions mismatch.
Expand Down
61 changes: 61 additions & 0 deletions calicoctl/calicoctl/resourcemgr/stagedglobalnetworkpolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// 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 resourcemgr

import (
"context"

api "github.com/projectcalico/api/pkg/apis/projectcalico/v3"

client "github.com/projectcalico/calico/libcalico-go/lib/clientv3"
"github.com/projectcalico/calico/libcalico-go/lib/options"
)

func init() {
registerResource(
api.NewStagedGlobalNetworkPolicy(),
api.NewStagedGlobalNetworkPolicyList(),
false,
[]string{"stagedglobalnetworkpolicy", "stagedglobalnetworkpolicies", "sgnp", "sgnps"},
[]string{"NAME", "TIER"},
[]string{"NAME", "TIER", "ORDER", "SELECTOR"},
map[string]string{
"NAME": "{{.ObjectMeta.Name}}",
"ORDER": "{{.Spec.Order}}",
"SELECTOR": "{{.Spec.Selector}}",
"TIER": "{{.Spec.Tier}}",
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedGlobalNetworkPolicy)
return client.StagedGlobalNetworkPolicies().Create(ctx, r, options.SetOptions{})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedGlobalNetworkPolicy)
return client.StagedGlobalNetworkPolicies().Update(ctx, r, options.SetOptions{})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedGlobalNetworkPolicy)
return client.StagedGlobalNetworkPolicies().Delete(ctx, r.Name, options.DeleteOptions{ResourceVersion: r.ResourceVersion})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedGlobalNetworkPolicy)
return client.StagedGlobalNetworkPolicies().Get(ctx, r.Name, options.GetOptions{ResourceVersion: r.ResourceVersion})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceListObject, error) {
r := resource.(*api.StagedGlobalNetworkPolicy)
return client.StagedGlobalNetworkPolicies().List(ctx, options.ListOptions{ResourceVersion: r.ResourceVersion, Name: r.Name})
},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// 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 resourcemgr

import (
"context"

api "github.com/projectcalico/api/pkg/apis/projectcalico/v3"

client "github.com/projectcalico/calico/libcalico-go/lib/clientv3"
"github.com/projectcalico/calico/libcalico-go/lib/options"
)

func init() {
registerResource(
api.NewStagedKubernetesNetworkPolicy(),
api.NewStagedKubernetesNetworkPolicyList(),
true,
[]string{"stagedkubernetesnetworkpolicy", "stagedkubernetesnetworkpolicies", "stagedkubernetespolicy", "sknp", "stagedkubernetespolicies", "skpol", "skpols"},
[]string{"NAME"},
[]string{"NAME", "PODSELECTOR"},
// NAMESPACE may be prepended in GrabTableTemplate so needs to remain in the map below
map[string]string{
"NAME": "{{.ObjectMeta.Name}}",
"NAMESPACE": "{{.ObjectMeta.Namespace}}",
"PODSELECTOR": "{{.Spec.PodSelector}}",
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedKubernetesNetworkPolicy)
return client.StagedKubernetesNetworkPolicies().Create(ctx, r, options.SetOptions{})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedKubernetesNetworkPolicy)
return client.StagedKubernetesNetworkPolicies().Update(ctx, r, options.SetOptions{})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedKubernetesNetworkPolicy)
return client.StagedKubernetesNetworkPolicies().Delete(ctx, r.Namespace, r.Name, options.DeleteOptions{ResourceVersion: r.ResourceVersion})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedKubernetesNetworkPolicy)
return client.StagedKubernetesNetworkPolicies().Get(ctx, r.Namespace, r.Name, options.GetOptions{ResourceVersion: r.ResourceVersion})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceListObject, error) {
r := resource.(*api.StagedKubernetesNetworkPolicy)
return client.StagedKubernetesNetworkPolicies().List(ctx, options.ListOptions{ResourceVersion: r.ResourceVersion, Namespace: r.Namespace, Name: r.Name})
},
)
}
63 changes: 63 additions & 0 deletions calicoctl/calicoctl/resourcemgr/stagednetworkpolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2019-2025 Tigera, Inc. All rights reserved.

// 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 resourcemgr

import (
"context"

api "github.com/projectcalico/api/pkg/apis/projectcalico/v3"

client "github.com/projectcalico/calico/libcalico-go/lib/clientv3"
"github.com/projectcalico/calico/libcalico-go/lib/options"
)

func init() {
registerResource(
api.NewStagedNetworkPolicy(),
api.NewStagedNetworkPolicyList(),
true,
[]string{"stagednetworkpolicy", "stagednetworkpolicies", "stagedpolicy", "snp", "stagedpolicies", "spol", "spols"},
[]string{"NAME", "TIER"},
[]string{"NAME", "TIER", "ORDER", "SELECTOR"},
// NAMESPACE may be prepended in GrabTableTemplate so needs to remain in the map below
map[string]string{
"NAME": "{{.ObjectMeta.Name}}",
"NAMESPACE": "{{.ObjectMeta.Namespace}}",
"ORDER": "{{.Spec.Order}}",
"SELECTOR": "{{.Spec.Selector}}",
"TIER": "{{.Spec.Tier}}",
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedNetworkPolicy)
return client.StagedNetworkPolicies().Create(ctx, r, options.SetOptions{})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedNetworkPolicy)
return client.StagedNetworkPolicies().Update(ctx, r, options.SetOptions{})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedNetworkPolicy)
return client.StagedNetworkPolicies().Delete(ctx, r.Namespace, r.Name, options.DeleteOptions{ResourceVersion: r.ResourceVersion})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceObject, error) {
r := resource.(*api.StagedNetworkPolicy)
return client.StagedNetworkPolicies().Get(ctx, r.Namespace, r.Name, options.GetOptions{ResourceVersion: r.ResourceVersion})
},
func(ctx context.Context, client client.Interface, resource ResourceObject) (ResourceListObject, error) {
r := resource.(*api.StagedNetworkPolicy)
return client.StagedNetworkPolicies().List(ctx, options.ListOptions{ResourceVersion: r.ResourceVersion, Namespace: r.Namespace, Name: r.Name})
},
)
}