Skip to content

Commit

Permalink
IP Access List CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
helderjs committed Jan 9, 2025
1 parent 3c9074e commit 9f70d8f
Show file tree
Hide file tree
Showing 11 changed files with 481 additions and 0 deletions.
13 changes: 13 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: mongodb.com
layout:
- go.kubebuilder.io/v4
Expand Down Expand Up @@ -113,4 +117,13 @@ resources:
kind: AtlasCustomRole
path: github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: mongodb.com
group: atlas
kind: AtlasIPAccessList
path: github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1
version: v1
version: "3"
110 changes: 110 additions & 0 deletions api/v1/atlasipaccesslist_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2025 MongoDB.
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 v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/status"
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/kube"
)

func init() {
SchemeBuilder.Register(&AtlasIPAccessList{}, &AtlasIPAccessListList{})
}

// AtlasIPAccessListSpec defines the desired state of AtlasIPAccessList.
type AtlasIPAccessListSpec struct {
// Project is a reference to AtlasProject resource the user belongs to
// +kubebuilder:validation:Optional
Project *common.ResourceRefNamespaced `json:"projectRef,omitempty"`
// ExternalProject holds the Atlas project ID the user belongs to
// +kubebuilder:validation:Optional
ExternalProject *ExternalProjectReference `json:"externalProjectRef,omitempty"`
// Local credentials
api.LocalCredentialHolder `json:",inline"`
// Entry using an IP address in this access list entry.
// +optional
IPAddress string `json:"ipAddress,omitempty"`
// Range of IP addresses in CIDR notation in this access list entry.
// +optional
CIDRBlock string `json:"cidrBlock,omitempty"`
// Unique identifier of AWS security group in this access list entry.
// +optional
AwsSecurityGroup string `json:"awsSecurityGroup,omitempty"`
// Timestamp in ISO 8601 date and time format in UTC after which Atlas deletes the temporary access list entry.
// +optional
DeleteAfterDate *metav1.Time `json:"deleteAfterDate,omitempty"`
// Comment associated with this access list entry.
// +optional
Comment string `json:"comment,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +groupName:=atlas.mongodb.com
// +kubebuilder:resource:categories=atlas,shortName=aial
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`

// AtlasIPAccessList is the Schema for the atlasipaccesslists API.
type AtlasIPAccessList struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AtlasIPAccessListSpec `json:"spec,omitempty"`
Status status.AtlasIPAccessListStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// AtlasIPAccessListList contains a list of AtlasIPAccessList.
type AtlasIPAccessListList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AtlasIPAccessList `json:"items"`
}

func (ial *AtlasIPAccessList) AtlasProjectObjectKey() client.ObjectKey {
ns := ial.Namespace
if ial.Spec.Project.Namespace != "" {
ns = ial.Spec.Project.Namespace
}

return kube.ObjectKey(ns, ial.Spec.Project.Name)
}

func (ial *AtlasIPAccessList) Credentials() *api.LocalObjectReference {
return ial.Spec.Credentials()
}

func (ial *AtlasIPAccessList) GetStatus() api.Status {
return ial.Status
}

func (ial *AtlasIPAccessList) UpdateStatus(conditions []api.Condition, options ...api.Option) {
ial.Status.Conditions = conditions
ial.Status.ObservedGeneration = ial.ObjectMeta.Generation

for _, o := range options {
v := o.(status.AtlasIPAccessListStatusOption)
v(&ial.Status)
}
}
32 changes: 32 additions & 0 deletions api/v1/status/atlasipaccesslist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2024 MongoDB.
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 status

import (
"github.com/mongodb/mongodb-atlas-kubernetes/v2/api"
)

// AtlasIPAccessListStatus is the most recent observed status of the AtlasIPAccessList cluster. Read-only.
type AtlasIPAccessListStatus struct {
api.Common `json:",inline"`
// Status is the state of the ip access list
Status string `json:"status,omitempty"`
}

// +kubebuilder:object:generate=false

type AtlasIPAccessListStatusOption func(s *AtlasIPAccessListStatus)
16 changes: 16 additions & 0 deletions api/v1/status/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f70d8f

Please sign in to comment.