diff --git a/go.mod b/go.mod index d3597972f..2116ac577 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/nmstate/kubernetes-nmstate/api v0.0.0-20240605150941-df565dd7bf35 github.com/onsi/ginkgo/v2 v2.19.0 github.com/onsi/gomega v1.33.1 - github.com/openshift-kni/eco-goinfra v0.0.0-20240910174952-7ae1f9d245ef // latest + github.com/openshift-kni/eco-goinfra v0.0.0-20240916124124-609263ee94e9 // latest github.com/openshift-kni/k8sreporter v1.0.5 github.com/openshift/api v3.9.1-0.20191111211345-a27ff30ebf09+incompatible github.com/openshift/cluster-nfd-operator v0.0.0-20240604082319-19bf50784aa7 diff --git a/go.sum b/go.sum index 942a5cc40..2467acf37 100644 --- a/go.sum +++ b/go.sum @@ -1264,8 +1264,8 @@ github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20240423171335-f07cdbf8af2c h1:wAPCXsnAXOUAJ5DYlVgGUcV9YBSiVlH4o9tbQ9py8ZY= github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20240423171335-f07cdbf8af2c/go.mod h1:hkzqKpmQvh7vgPx8Hw6IExJorKPM0dEeJdOXjIW3gNw= -github.com/openshift-kni/eco-goinfra v0.0.0-20240910174952-7ae1f9d245ef h1:ZFLkBtKwvPYUVza8Vb+UiX8fXRstFvW/q8MlBu+HjCM= -github.com/openshift-kni/eco-goinfra v0.0.0-20240910174952-7ae1f9d245ef/go.mod h1:HX/xlfTNEq0qdf/wTHVV6munJPrvojndY+Mi1zC7kM4= +github.com/openshift-kni/eco-goinfra v0.0.0-20240916124124-609263ee94e9 h1:wQFGvOZYQY5fs2TtXCpSKDTRrLHXau7fdfNkqoOJkuM= +github.com/openshift-kni/eco-goinfra v0.0.0-20240916124124-609263ee94e9/go.mod h1:zDXl8Zv+Na44BvHTaCJdeD2ZI0poDe367tB/UA9xh7w= github.com/openshift-kni/k8sreporter v1.0.5 h1:1GYBc/BTZyVoXilHef43v9A8BSzw700zAPZ6zsZvo6Y= github.com/openshift-kni/k8sreporter v1.0.5/go.mod h1:fg8HI9yxiKAi6UzR6NTtrmQmA2WKzUqmkRUHwQ1+Bj8= github.com/openshift-kni/lifecycle-agent v0.0.0-20240606123201-0c45cd13c2f1 h1:y+0Ecc+MSZA/GNS3VOpKq+XK9x8qoNA7TlyHvqbVbpw= diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmh/hfs.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmh/hfs.go new file mode 100644 index 000000000..0835e2299 --- /dev/null +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmh/hfs.go @@ -0,0 +1,196 @@ +package bmh + +import ( + "context" + "fmt" + + "github.com/golang/glog" + bmhv1alpha1 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" + "github.com/openshift-kni/eco-goinfra/pkg/clients" + "github.com/openshift-kni/eco-goinfra/pkg/msg" + k8serrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + goclient "sigs.k8s.io/controller-runtime/pkg/client" +) + +// HFSBuilder provides a struct to interface with HostFirmwareSettings resources on a specific cluster. +type HFSBuilder struct { + // Definition of the HostFirmwareSettings used to create the object. + Definition *bmhv1alpha1.HostFirmwareSettings + // Object of the HostFirmwareSettings as it is on the cluster. + Object *bmhv1alpha1.HostFirmwareSettings + apiClient goclient.Client + errorMsg string +} + +// PullHFS pulls an existing HostFirmwareSettings from the cluster. +func PullHFS(apiClient *clients.Settings, name, nsname string) (*HFSBuilder, error) { + glog.V(100).Infof("Pulling existing HostFirmwareSettings name %s under namespace %s from cluster", name, nsname) + + if apiClient == nil { + glog.V(100).Infof("The apiClient is nil") + + return nil, fmt.Errorf("hostFirmwareSettings 'apiClient' cannot be nil") + } + + err := apiClient.AttachScheme(bmhv1alpha1.AddToScheme) + if err != nil { + glog.V(100).Infof("Failed to add bmhv1alpha1 scheme to client schemes") + + return nil, err + } + + builder := HFSBuilder{ + apiClient: apiClient.Client, + Definition: &bmhv1alpha1.HostFirmwareSettings{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: nsname, + }, + }, + } + + if name == "" { + glog.V(100).Infof("The name of the HostFirmwareSettings is empty") + + return nil, fmt.Errorf("hostFirmwareSettings 'name' cannot be empty") + } + + if nsname == "" { + glog.V(100).Infof("The nsname of the HostFirmwareSettings is empty") + + return nil, fmt.Errorf("hostFirmwareSettings 'nsname' cannot be empty") + } + + if !builder.Exists() { + return nil, fmt.Errorf("hostFirmwareSettings object %s does not exist in namespace %s", name, nsname) + } + + builder.Definition = builder.Object + + return &builder, nil +} + +// Get returns the HostFirmwareSettings object if found. +func (builder *HFSBuilder) Get() (*bmhv1alpha1.HostFirmwareSettings, error) { + if valid, err := builder.validate(); !valid { + return nil, err + } + + glog.V(100).Infof( + "Getting HostFirmwareSettings object %s in namespace %s", builder.Definition.Name, builder.Definition.Namespace) + + hostFirmwareSettings := &bmhv1alpha1.HostFirmwareSettings{} + err := builder.apiClient.Get(context.TODO(), goclient.ObjectKey{ + Name: builder.Definition.Name, + Namespace: builder.Definition.Namespace, + }, hostFirmwareSettings) + + if err != nil { + glog.V(100).Infof( + "HostFirmwareSettings object %s does not exist in namespace %s", + builder.Definition.Name, builder.Definition.Namespace) + + return nil, err + } + + return hostFirmwareSettings, nil +} + +// Exists checks whether the given HostFirmwareSettings exists on the cluster. +func (builder *HFSBuilder) Exists() bool { + if valid, _ := builder.validate(); !valid { + return false + } + + glog.V(100).Infof( + "Checking if HostFirmwareSettings %s exists in namespace %s", builder.Definition.Name, builder.Definition.Namespace) + + var err error + builder.Object, err = builder.Get() + + return err == nil || !k8serrors.IsNotFound(err) +} + +// Create makes a HostFirmwareSettings on the cluster if it does not already exist. +func (builder *HFSBuilder) Create() (*HFSBuilder, error) { + if valid, err := builder.validate(); !valid { + return nil, err + } + + glog.V(100).Infof( + "Creating HostFirmwareSettings %s in namespace %s", builder.Definition.Name, builder.Definition.Namespace) + + if builder.Exists() { + return builder, nil + } + + err := builder.apiClient.Create(context.TODO(), builder.Definition) + if err != nil { + return nil, err + } + + builder.Object = builder.Definition + + return builder, err +} + +// Delete removes a HostFirmwareSettings from the cluster if it exists. +func (builder *HFSBuilder) Delete() error { + if valid, err := builder.validate(); !valid { + return err + } + + glog.V(100).Infof( + "Deleting HostFirmwareSettings %s in namespace %s", builder.Definition.Name, builder.Definition.Namespace) + + if !builder.Exists() { + glog.V(100).Infof( + "HostFirmwareSettings %s in namespace %s does not exist", + builder.Definition.Name, builder.Definition.Namespace) + + builder.Object = nil + + return nil + } + + err := builder.apiClient.Delete(context.TODO(), builder.Object) + if err != nil { + return err + } + + builder.Object = nil + + return nil +} + +// validate checks that the builder, definition, and apiClient are properly initialized and there is no errorMsg. +func (builder *HFSBuilder) validate() (bool, error) { + resourceCRD := "hostFirmwareSettings" + + if builder == nil { + glog.V(100).Infof("The %s builder is uninitialized", resourceCRD) + + return false, fmt.Errorf("error: received nil %s builder", resourceCRD) + } + + if builder.Definition == nil { + glog.V(100).Infof("The %s is uninitialized", resourceCRD) + + return false, fmt.Errorf(msg.UndefinedCrdObjectErrString(resourceCRD)) + } + + if builder.apiClient == nil { + glog.V(100).Infof("The %s builder apiClient is nil", resourceCRD) + + return false, fmt.Errorf("%s builder cannot have nil apiClient", resourceCRD) + } + + if builder.errorMsg != "" { + glog.V(100).Infof("The %s builder has error message %s", resourceCRD, builder.errorMsg) + + return false, fmt.Errorf(builder.errorMsg) + } + + return true, nil +} diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/nodes/node.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/nodes/node.go index 0942f9650..0ca6cf620 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/nodes/node.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/nodes/node.go @@ -117,6 +117,12 @@ type AdditionalOptions func(builder *Builder) (*Builder, error) func Pull(apiClient *clients.Settings, nodeName string) (*Builder, error) { glog.V(100).Infof("Pulling existing node object: %s", nodeName) + if apiClient == nil { + glog.V(100).Info("The node apiClient is nil") + + return nil, fmt.Errorf("node 'apiClient' cannot be nil") + } + builder := Builder{ apiClient: apiClient.K8sClient, Definition: &corev1.Node{ @@ -126,6 +132,12 @@ func Pull(apiClient *clients.Settings, nodeName string) (*Builder, error) { }, } + if nodeName == "" { + glog.V(100).Info("The name of the node is empty") + + return nil, fmt.Errorf("node 'name' cannot be empty") + } + if !builder.Exists() { return nil, fmt.Errorf("node object %s does not exist", nodeName) } @@ -181,7 +193,11 @@ func (builder *Builder) Delete() error { glog.V(100).Infof("Deleting the node %s", builder.Definition.Name) if !builder.Exists() { - return fmt.Errorf("node cannot be deleted because it does not exist") + glog.V(100).Info("Cannot delete node %s if it does not exist", builder.Definition.Name) + + builder.Object = nil + + return nil } err := builder.apiClient.CoreV1().Nodes().Delete( @@ -285,11 +301,11 @@ func (builder *Builder) ExternalIPv4Network() (string, error) { glog.V(100).Infof("Collecting node's external ipv4 addresses") if builder.Object == nil { - builder.errorMsg = "error to collect external networks from node" + return "", fmt.Errorf("cannot collect external networks when node object is nil") } - if builder.errorMsg != "" { - return "", fmt.Errorf(builder.errorMsg) + if _, ok := builder.Object.Annotations[ovnExternalAddresses]; !ok { + return "", fmt.Errorf("node %s does not have external addresses annotation", builder.Definition.Name) } var extNetwork ExternalNetworks @@ -312,7 +328,7 @@ func (builder *Builder) IsReady() (bool, error) { glog.V(100).Infof("Verify %s node availability", builder.Definition.Name) if !builder.Exists() { - return false, fmt.Errorf("%s node object does not exist", builder.Definition.Name) + return false, fmt.Errorf("node object %s does not exist", builder.Definition.Name) } for _, condition := range builder.Object.Status.Conditions { @@ -331,7 +347,7 @@ func (builder *Builder) WaitUntilConditionTrue( return err } - err := wait.PollUntilContextTimeout( + return wait.PollUntilContextTimeout( context.TODO(), time.Second, timeout, true, func(ctx context.Context) (bool, error) { if !builder.Exists() { return false, fmt.Errorf("node %s object does not exist", builder.Definition.Name) @@ -344,25 +360,19 @@ func (builder *Builder) WaitUntilConditionTrue( } return false, fmt.Errorf("the %s condition could not be found for node %s", - builder.Definition.Name, conditionType) + conditionType, builder.Definition.Name) }) - - if err == nil { - return nil - } - - return fmt.Errorf("%s node condition %s never became True due to %w", - builder.Definition.Name, conditionType, err) } -// WaitUntilConditionUnknown waits for timeout duration or until node change specific status. +// WaitUntilConditionUnknown waits for timeout duration or until the provided condition type does not have status +// Unknown. func (builder *Builder) WaitUntilConditionUnknown( conditionType corev1.NodeConditionType, timeout time.Duration) error { if valid, err := builder.validate(); !valid { return err } - err := wait.PollUntilContextTimeout( + return wait.PollUntilContextTimeout( context.TODO(), time.Second, timeout, true, func(ctx context.Context) (bool, error) { if !builder.Exists() { return false, fmt.Errorf("node %s object does not exist", builder.Definition.Name) @@ -375,15 +385,8 @@ func (builder *Builder) WaitUntilConditionUnknown( } return false, fmt.Errorf("the %s condition could not be found for node %s", - builder.Definition.Name, conditionType) + conditionType, builder.Definition.Name) }) - - if err == nil { - return nil - } - - return fmt.Errorf("%s node condition %s never became Unknown due to %w", - builder.Definition.Name, conditionType, err) } // WaitUntilReady waits for timeout duration or until node is Ready. @@ -399,7 +402,7 @@ func (builder *Builder) WaitUntilNotReady(timeout time.Duration) error { // validate will check that the builder and builder definition are properly initialized before // accessing any member fields. func (builder *Builder) validate() (bool, error) { - resourceCRD := "Node" + resourceCRD := "node" if builder == nil { glog.V(100).Infof("The %s builder is uninitialized", resourceCRD) diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/clusterrole.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/clusterrole.go index 18223f75b..4beaedb9d 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/clusterrole.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/clusterrole.go @@ -44,7 +44,6 @@ func NewClusterRoleBuilder(apiClient *clients.Settings, name string, rule v1.Pol ObjectMeta: metav1.ObjectMeta{ Name: name, }, - Rules: []v1.PolicyRule{rule}, }, } @@ -130,6 +129,12 @@ func (builder *ClusterRoleBuilder) WithOptions(options ...ClusterRoleAdditionalO func PullClusterRole(apiClient *clients.Settings, name string) (*ClusterRoleBuilder, error) { glog.V(100).Infof("Pulling existing clusterrole name %s from cluster", name) + if apiClient == nil { + glog.V(100).Infof("The apiClient cannot be nil") + + return nil, fmt.Errorf("the apiClient cannot be nil") + } + builder := ClusterRoleBuilder{ apiClient: apiClient, Definition: &v1.ClusterRole{ @@ -142,7 +147,7 @@ func PullClusterRole(apiClient *clients.Settings, name string) (*ClusterRoleBuil if name == "" { glog.V(100).Infof("The name of the clusterrole is empty") - builder.errorMsg = "clusterrole 'name' cannot be empty" + return nil, fmt.Errorf("clusterrole 'name' cannot be empty") } if !builder.Exists() { @@ -206,6 +211,10 @@ func (builder *ClusterRoleBuilder) Update() (*ClusterRoleBuilder, error) { glog.V(100).Infof("Updating clusterrole %s", builder.Definition.Name) + if !builder.Exists() { + return nil, fmt.Errorf("clusterrole object %s does not exist, fail to update", builder.Definition.Name) + } + var err error builder.Object, err = builder.apiClient.ClusterRoles().Update( context.TODO(), builder.Definition, metav1.UpdateOptions{}) @@ -232,7 +241,7 @@ func (builder *ClusterRoleBuilder) Exists() bool { // validate will check that the builder and builder definition are properly initialized before // accessing any member fields. func (builder *ClusterRoleBuilder) validate() (bool, error) { - resourceCRD := "ClusterRole" + resourceCRD := "clusterRole" if builder == nil { glog.V(100).Infof("The %s builder is uninitialized", resourceCRD) diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/role.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/role.go index d53268128..9956cdf03 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/role.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/rbac/role.go @@ -34,7 +34,7 @@ func NewRoleBuilder(apiClient *clients.Settings, name, nsname string, rule v1.Po "Initializing new role structure with the following params: "+ "name: %s, namespace: %s, rule %v", name, nsname, rule) - builder := RoleBuilder{ + builder := &RoleBuilder{ apiClient: apiClient, Definition: &v1.Role{ ObjectMeta: metav1.ObjectMeta{ @@ -47,18 +47,22 @@ func NewRoleBuilder(apiClient *clients.Settings, name, nsname string, rule v1.Po if name == "" { glog.V(100).Infof("The name of the role is empty") - builder.errorMsg = "Role 'name' cannot be empty" + builder.errorMsg = "role 'name' cannot be empty" + + return builder } if nsname == "" { glog.V(100).Infof("The namespace of the role is empty") - builder.errorMsg = "Role 'nsname' cannot be empty" + builder.errorMsg = "role 'nsname' cannot be empty" + + return builder } builder.WithRules([]v1.PolicyRule{rule}) - return &builder + return builder } // WithRules adds the specified PolicyRule to the Role. @@ -143,6 +147,12 @@ func (builder *RoleBuilder) WithOptions( func PullRole(apiClient *clients.Settings, name, nsname string) (*RoleBuilder, error) { glog.V(100).Infof("Pulling existing role name %s under namespace %s from cluster", name, nsname) + if apiClient == nil { + glog.V(100).Infof("The apiClient cannot be nil") + + return nil, fmt.Errorf("the apiClient cannot be nil") + } + builder := RoleBuilder{ apiClient: apiClient, Definition: &v1.Role{ @@ -156,13 +166,13 @@ func PullRole(apiClient *clients.Settings, name, nsname string) (*RoleBuilder, e if name == "" { glog.V(100).Infof("The name of the role is empty") - builder.errorMsg = "role 'name' cannot be empty" + return nil, fmt.Errorf("role 'name' cannot be empty") } if nsname == "" { glog.V(100).Infof("The namespace of the role is empty") - builder.errorMsg = "role 'namespace' cannot be empty" + return nil, fmt.Errorf("role 'namespace' cannot be empty") } if !builder.Exists() { @@ -226,6 +236,10 @@ func (builder *RoleBuilder) Update() (*RoleBuilder, error) { glog.V(100).Infof("Updating role %s under namespace %s", builder.Definition.Name, builder.Definition.Namespace) + if !builder.Exists() { + return nil, fmt.Errorf("role object %s does not exist, fail to update", builder.Definition.Name) + } + var err error builder.Object, err = builder.apiClient.Roles(builder.Definition.Namespace).Update( context.TODO(), builder.Definition, metav1.UpdateOptions{}) @@ -252,7 +266,7 @@ func (builder *RoleBuilder) Exists() bool { // validate will check that the builder and builder definition are properly initialized before // accessing any member fields. func (builder *RoleBuilder) validate() (bool, error) { - resourceCRD := "Role" + resourceCRD := "role" if builder == nil { glog.V(100).Infof("The %s builder is uninitialized", resourceCRD) diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/scc/scc.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/scc/scc.go index d7f7564ff..4c6a8cb28 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/scc/scc.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/scc/scc.go @@ -11,6 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + goclient "sigs.k8s.io/controller-runtime/pkg/client" ) const redefiningMsg = "Redefining SecurityContextConstraints" @@ -37,7 +38,20 @@ func NewBuilder(apiClient *clients.Settings, name, runAsUser, selinuxContext str "Initializing new SecurityContextConstraints structure with the following params: "+ "name: %s, runAsUser type: %s, selinuxContext type: %s", name, runAsUser, selinuxContext) - builder := Builder{ + if apiClient == nil { + glog.V(100).Infof("The apiClient cannot be nil") + + return nil + } + + err := apiClient.AttachScheme(securityV1.Install) + if err != nil { + glog.V(100).Infof("Failed to add security v1 scheme to client schemes") + + return nil + } + + builder := &Builder{ apiClient: apiClient, Definition: &securityV1.SecurityContextConstraints{ ObjectMeta: metav1.ObjectMeta{ @@ -55,28 +69,47 @@ func NewBuilder(apiClient *clients.Settings, name, runAsUser, selinuxContext str if name == "" { glog.V(100).Infof("The name of the SecurityContextConstraints is empty") - builder.errorMsg = "SecurityContextConstraints 'name' cannot be empty" + builder.errorMsg = "securityContextConstraints 'name' cannot be empty" + + return builder } if runAsUser == "" { glog.V(100).Infof("The runAsUser of the SecurityContextConstraints is empty") - builder.errorMsg = "SecurityContextConstraints 'runAsUser' cannot be empty" + builder.errorMsg = "securityContextConstraints 'runAsUser' cannot be empty" + + return builder } if selinuxContext == "" { glog.V(100).Infof("The selinuxContext of the SecurityContextConstraints is empty") - builder.errorMsg = "SecurityContextConstraints 'selinuxContext' cannot be empty" + builder.errorMsg = "securityContextConstraints 'selinuxContext' cannot be empty" + + return builder } - return &builder + return builder } // Pull pulls existing SecurityContextConstraints from cluster. func Pull(apiClient *clients.Settings, name string) (*Builder, error) { glog.V(100).Infof("Pulling existing SecurityContextConstraints object name %s from cluster", name) + if apiClient == nil { + glog.V(100).Infof("The apiClient cannot be nil") + + return nil, fmt.Errorf("the apiClient cannot be nil") + } + + err := apiClient.AttachScheme(securityV1.Install) + if err != nil { + glog.V(100).Infof("Failed to add security v1 scheme to client schemes") + + return nil, fmt.Errorf("failed to add security v1 scheme to client schemes") + } + builder := Builder{ apiClient: apiClient, Definition: &securityV1.SecurityContextConstraints{ @@ -89,11 +122,11 @@ func Pull(apiClient *clients.Settings, name string) (*Builder, error) { if name == "" { glog.V(100).Infof("The name of the SecurityContextConstraints is empty") - builder.errorMsg = "SecurityContextConstraints 'name' cannot be empty" + return nil, fmt.Errorf("securityContextConstraints 'name' cannot be empty") } if !builder.Exists() { - return nil, fmt.Errorf("SecurityContextConstraints object %s does not exist", name) + return nil, fmt.Errorf("securityContextConstraints object %s does not exist", name) } builder.Definition = builder.Object @@ -224,7 +257,7 @@ func (builder *Builder) WithDropCapabilities(requiredDropCapabilities []corev1.C if len(requiredDropCapabilities) == 0 { glog.V(100).Infof("SecurityContextConstraints 'requiredDropCapabilities' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'requiredDropCapabilities' cannot be empty list" + builder.errorMsg = "securityContextConstraints 'requiredDropCapabilities' cannot be empty list" return builder } @@ -253,7 +286,7 @@ func (builder *Builder) WithAllowCapabilities(allowCapabilities []corev1.Capabil if len(allowCapabilities) == 0 { glog.V(100).Infof("SecurityContextConstraints 'allowCapabilities' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'allowCapabilities' cannot be empty list" + builder.errorMsg = "securityContextConstraints 'allowCapabilities' cannot be empty list" return builder } @@ -281,7 +314,7 @@ func (builder *Builder) WithDefaultAddCapabilities(defaultAddCapabilities []core if len(defaultAddCapabilities) == 0 { glog.V(100).Infof("SecurityContextConstraints 'defaultAddCapabilities' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'defaultAddCapabilities' cannot be empty list" + builder.errorMsg = "securityContextConstraints 'defaultAddCapabilities' cannot be empty list" return builder } @@ -322,7 +355,7 @@ func (builder *Builder) WithFSGroup(fsGroup string) *Builder { if fsGroup == "" { glog.V(100).Infof("SecurityContextConstraints 'fsGroup' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'fsGroup' cannot be empty string" + builder.errorMsg = "securityContextConstraints 'fsGroup' cannot be empty string" return builder } @@ -344,7 +377,7 @@ func (builder *Builder) WithFSGroupRange(fsGroupMin, fsGroupMax int64) *Builder if fsGroupMin > fsGroupMax { glog.V(100).Infof("SecurityContextConstraints 'fsGroupMin' argument can not be greater than fsGroupMax") - builder.errorMsg = "SecurityContextConstraints 'fsGroupMin' argument can not be greater than fsGroupMax" + builder.errorMsg = "securityContextConstraints 'fsGroupMin' argument can not be greater than fsGroupMax" return builder } @@ -372,7 +405,7 @@ func (builder *Builder) WithGroups(groups []string) *Builder { if len(groups) == 0 { glog.V(100).Infof("SecurityContextConstraints 'groups' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'fsGroupType' cannot be empty string" + builder.errorMsg = "securityContextConstraints 'fsGroupType' cannot be empty string" return builder } @@ -400,7 +433,7 @@ func (builder *Builder) WithSeccompProfiles(seccompProfiles []string) *Builder { if len(seccompProfiles) == 0 { glog.V(100).Infof("SecurityContextConstraints 'seccompProfiles' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'seccompProfiles' cannot be empty list" + builder.errorMsg = "securityContextConstraints 'seccompProfiles' cannot be empty list" return builder } @@ -428,7 +461,7 @@ func (builder *Builder) WithSupplementalGroups(supplementalGroupsType string) *B if supplementalGroupsType == "" { glog.V(100).Infof("SecurityContextConstraints 'SupplementalGroups' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'SupplementalGroups' cannot be empty string" + builder.errorMsg = "securityContextConstraints 'SupplementalGroups' cannot be empty string" return builder } @@ -449,7 +482,7 @@ func (builder *Builder) WithUsers(users []string) *Builder { if len(users) == 0 { glog.V(100).Infof("SecurityContextConstraints 'users' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'users' cannot be empty list" + builder.errorMsg = "securityContextConstraints 'users' cannot be empty list" return builder } @@ -476,7 +509,7 @@ func (builder *Builder) WithVolumes(volumes []securityV1.FSType) *Builder { if len(volumes) == 0 { glog.V(100).Infof("SecurityContextConstraints 'volumes' argument cannot be empty") - builder.errorMsg = "SecurityContextConstraints 'volumes' cannot be empty list" + builder.errorMsg = "securityContextConstraints 'volumes' cannot be empty list" return builder } @@ -502,10 +535,17 @@ func (builder *Builder) Create() (*Builder, error) { var err error if !builder.Exists() { - builder.Object, err = builder.apiClient.SecurityContextConstraints().Create( - context.TODO(), builder.Definition, metav1.CreateOptions{}) + err = builder.apiClient.Create(context.TODO(), builder.Definition) + + if err != nil { + glog.V(100).Infof("Failed to create SecurityContextConstraints") + + return nil, err + } } + builder.Object = builder.Definition + return builder, err } @@ -521,8 +561,7 @@ func (builder *Builder) Delete() error { return nil } - err := builder.apiClient.SecurityContextConstraints().Delete( - context.TODO(), builder.Object.Name, metav1.DeleteOptions{}) + err := builder.apiClient.Delete(context.TODO(), builder.Definition) builder.Object = nil @@ -537,13 +576,35 @@ func (builder *Builder) Update() (*Builder, error) { glog.V(100).Infof("Updating SecurityContextConstraints %s ", builder.Definition.Name) - var err error - builder.Object, err = builder.apiClient.SecurityContextConstraints().Update( - context.TODO(), builder.Definition, metav1.UpdateOptions{}) + if !builder.Exists() { + return nil, fmt.Errorf("failed to update SecurityContextConstraints, object does not exist on cluster") + } + + err := builder.apiClient.Update(context.TODO(), builder.Definition) return builder, err } +// Get returns NMState object if found. +func (builder *Builder) Get() (*securityV1.SecurityContextConstraints, error) { + if valid, err := builder.validate(); !valid { + return nil, err + } + + glog.V(100).Infof("Collecting SecurityContextConstraints object %s", builder.Definition.Name) + + scc := &securityV1.SecurityContextConstraints{} + err := builder.apiClient.Get(context.TODO(), goclient.ObjectKey{Name: builder.Definition.Name}, scc) + + if err != nil { + glog.V(100).Infof("SecurityContextConstraints object %s does not exist", builder.Definition.Name) + + return nil, err + } + + return scc, err +} + // Exists checks whether the given SecurityContextConstraints exists. func (builder *Builder) Exists() bool { if valid, _ := builder.validate(); !valid { @@ -553,8 +614,11 @@ func (builder *Builder) Exists() bool { glog.V(100).Infof("Checking if SecurityContextConstraints %s exists", builder.Definition.Name) var err error - builder.Object, err = builder.apiClient.SecurityContextConstraints().Get( - context.TODO(), builder.Definition.Name, metav1.GetOptions{}) + builder.Object, err = builder.Get() + + if err != nil { + glog.V(100).Infof("Failed to collect SecurityContextConstraints object due to %s", err.Error()) + } return err == nil || !k8serrors.IsNotFound(err) } diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/agent_types.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/agent_types.go index f7a607c14..e80c25528 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/agent_types.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/agent_types.go @@ -227,6 +227,13 @@ type HostNTPSources struct { SourceState models.SourceState `json:"sourceState,omitempty"` } +type AgentDeprovisionInfo struct { + ClusterName string `json:"cluster_name,omitempty"` + ClusterNamespace string `json:"cluster_namespace,omitempty"` + NodeName string `json:"node_name,omitempty"` + Message string `json:"message,omitempty"` +} + // AgentStatus defines the observed state of Agent type AgentStatus struct { Bootstrap bool `json:"bootstrap,omitempty"` @@ -247,6 +254,10 @@ type AgentStatus struct { // InstallationDiskID is the disk that will be used for the installation. // +optional InstallationDiskID string `json:"installation_disk_id,omitempty"` + + // DeprovisionInfo stores data related to the agent's previous cluster binding in order to clean up when the agent re-registers + // +optional + DeprovisionInfo *AgentDeprovisionInfo `json:"deprovision_info,omitempty"` } type DebugInfo struct { diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/zz_generated.deepcopy.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/zz_generated.deepcopy.go index dacb48e2f..9454edccc 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/zz_generated.deepcopy.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/assisted/api/v1beta1/zz_generated.deepcopy.go @@ -152,6 +152,21 @@ func (in *AgentClassificationStatus) DeepCopy() *AgentClassificationStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AgentDeprovisionInfo) DeepCopyInto(out *AgentDeprovisionInfo) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AgentDeprovisionInfo. +func (in *AgentDeprovisionInfo) DeepCopy() *AgentDeprovisionInfo { + if in == nil { + return nil + } + out := new(AgentDeprovisionInfo) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AgentList) DeepCopyInto(out *AgentList) { *out = *in @@ -394,6 +409,11 @@ func (in *AgentStatus) DeepCopyInto(out *AgentStatus) { (*out)[key] = outVal } } + if in.DeprovisionInfo != nil { + in, out := &in.DeprovisionInfo, &out.DeprovisionInfo + *out = new(AgentDeprovisionInfo) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AgentStatus. diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocm/kacv1/types.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocm/kacv1/types.go index 3cbd2ea0b..e5b09a63e 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocm/kacv1/types.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocm/kacv1/types.go @@ -79,3 +79,23 @@ var KlusterletAddonImageNames = map[string][]string{ PolicyFrameworkAddonName: {"governance_policy_framework_addon", "kube_rbac_proxy"}, SearchAddonName: {"search_collector"}, } + +// image env names +const ( + EnvMulticlusterOperatorSubscription = "MULTICLUSTER_OPERATOR_SUBSCRIPTION" + EnvConfigPolicyController = "CONFIG_POLICY_CONTROLLER" + EnvKubeRBACProxy = "KUBE_RBAC_PROXY" + EnvCertPolicyController = "CERT_POLICY_CONTROLLER" + EnvGovernancePolicyFrameworkAddon = "GOVERNANCE_POLICY_FRAMEWORK_ADDON" + EnvSearchCollector = "SEARCH_COLLECTOR" +) + +// EnvImageNameMap is the image env names map +var EnvImageNameMap = map[string]string{ + EnvMulticlusterOperatorSubscription: "multicluster_operators_subscription", + EnvKubeRBACProxy: "kube_rbac_proxy", + EnvCertPolicyController: "cert_policy_controller", + EnvConfigPolicyController: "config_policy_controller", + EnvGovernancePolicyFrameworkAddon: "governance_policy_framework_addon", + EnvSearchCollector: "search_collector", +} diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/nadutils/net-attach-def.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/nadutils/net-attach-def.go index 27bfd1d8a..cc5c8acf0 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/nadutils/net-attach-def.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/nadutils/net-attach-def.go @@ -149,11 +149,12 @@ func CreateNetworkStatuses(r cnitypes.Result, networkName string, defaultNetwork // Initialize NetworkStatus for each container interface (e.g. with sandbox present) indexOfFoundPodInterface := 0 + foundFirstSandboxIface := false for i, iface := range result.Interfaces { if iface.Sandbox != "" { ns := &v1.NetworkStatus{ Name: networkName, - Default: defaultNetwork, + Default: defaultNetwork && !foundFirstSandboxIface, Interface: iface.Name, Mac: iface.Mac, Mtu: iface.Mtu, @@ -166,6 +167,7 @@ func CreateNetworkStatuses(r cnitypes.Result, networkName string, defaultNetwork // Map original index to the new slice index indexMap[i] = indexOfFoundPodInterface indexOfFoundPodInterface++ + foundFirstSandboxIface = true } } diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/storagecluster_types.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/storagecluster_types.go index 056ea4fa4..1bc713ff5 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/storagecluster_types.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/storagecluster_types.go @@ -86,7 +86,7 @@ type StorageClusterSpec struct { Arbiter ArbiterSpec `json:"arbiter,omitempty"` // Mirroring specifies data mirroring configuration for the storage cluster. // This configuration will only be applied to resources managed by the operator. - Mirroring MirroringSpec `json:"mirroring,omitempty"` + Mirroring *MirroringSpec `json:"mirroring,omitempty"` // OverprovisionControl specifies the allowed hard-limit PVs overprovisioning relative to // the effective usable storage capacity. OverprovisionControl []OverprovisionControlSpec `json:"overprovisionControl,omitempty"` diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/zz_generated.deepcopy.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/zz_generated.deepcopy.go index 363aee493..f0e395921 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/zz_generated.deepcopy.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/schemes/ocs/operatorv1/zz_generated.deepcopy.go @@ -1048,7 +1048,11 @@ func (in *StorageClusterSpec) DeepCopyInto(out *StorageClusterSpec) { (*in).DeepCopyInto(*out) } in.Arbiter.DeepCopyInto(&out.Arbiter) - in.Mirroring.DeepCopyInto(&out.Mirroring) + if in.Mirroring != nil { + in, out := &in.Mirroring, &out.Mirroring + *out = new(MirroringSpec) + (*in).DeepCopyInto(*out) + } if in.OverprovisionControl != nil { in, out := &in.OverprovisionControl, &out.OverprovisionControl *out = make([]OverprovisionControlSpec, len(*in)) diff --git a/vendor/modules.txt b/vendor/modules.txt index b5862a0af..5bbc56918 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -521,7 +521,7 @@ github.com/onsi/gomega/types ## explicit; go 1.20 github.com/openshift-kni/cluster-group-upgrades-operator/pkg/api/clustergroupupgrades github.com/openshift-kni/cluster-group-upgrades-operator/pkg/api/clustergroupupgrades/v1alpha1 -# github.com/openshift-kni/eco-goinfra v0.0.0-20240910174952-7ae1f9d245ef +# github.com/openshift-kni/eco-goinfra v0.0.0-20240916124124-609263ee94e9 ## explicit; go 1.22 github.com/openshift-kni/eco-goinfra/pkg/apiservers github.com/openshift-kni/eco-goinfra/pkg/argocd