Skip to content

Commit

Permalink
Merge pull request #189 from periklis/backport-pr-10562-to-5.7
Browse files Browse the repository at this point in the history
[release-5.7] Backport PR grafana#10562
  • Loading branch information
openshift-merge-robot authored Oct 2, 2023
2 parents c6bf332 + dc2cecf commit 7c859fe
Show file tree
Hide file tree
Showing 23 changed files with 467 additions and 10 deletions.
1 change: 1 addition & 0 deletions operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Release 5.7.7

- [10562](https://github.com/grafana/loki/pull/10562) **periklis**: Add memberlist IPv6 support
- [10600](https://github.com/grafana/loki/pull/10600) **periklis**: Update Loki operand to v2.9.1

## Release 5.7.6
Expand Down
10 changes: 10 additions & 0 deletions operator/apis/loki/v1/lokistack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ type MemberListSpec struct {
// +kubebuilder:validation:optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:select:default","urn:alm:descriptor:com.tectonic.ui:select:podIP"},displayName="Instance Address"
InstanceAddrType InstanceAddrType `json:"instanceAddrType,omitempty"`

// EnableIPv6 enables IPv6 support for the memberlist based hash ring.
//
// Currently this also forces the instanceAddrType to podIP to avoid local address lookup
// for the memberlist.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch",displayName="Enable IPv6"
EnableIPv6 bool `json:"enableIPv6,omitempty"`
}

// HashRingSpec defines the hash ring configuration
Expand Down
2 changes: 2 additions & 0 deletions operator/apis/loki/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ var (
ErrSchemaRetroactivelyChanged = errors.New("Cannot retroactively change schema")
// ErrHeaderAuthCredentialsConflict when both Credentials and CredentialsFile are used in a header authentication client.
ErrHeaderAuthCredentialsConflict = errors.New("credentials and credentialsFile cannot be used at the same time")
// ErrIPv6InstanceAddrTypeNotAllowed when the default InstanceAddrType is used with enableIPv6.
ErrIPv6InstanceAddrTypeNotAllowed = errors.New(`instanceAddrType "default" cannot be used with enableIPv6 at the same time`)

// ErrRuleMustMatchNamespace indicates that an expression used in an alerting or recording rule is missing
// matchers for a namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: docker.io/grafana/loki-operator:main-99acb9b
createdAt: "2023-09-16T14:40:42Z"
createdAt: "2023-10-02T09:34:50Z"
description: The Community Loki Operator provides Kubernetes native deployment
and management of Loki and related logging components.
operators.operatorframework.io/builder: operator-sdk-unknown
Expand Down Expand Up @@ -265,6 +265,13 @@ spec:
- description: MemberList configuration spec
displayName: Memberlist Config
path: hashRing.memberlist
- description: "EnableIPv6 enables IPv6 support for the memberlist based hash
ring. \n Currently this also forces the instanceAddrType to podIP to avoid
local address lookup for the memberlist."
displayName: Enable IPv6
path: hashRing.memberlist.enableIPv6
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: InstanceAddrType defines the type of address to use to advertise
to the ring. Defaults to the first address from any private network interfaces
of the current pod. Alternatively the public pod IP can be used in case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ spec:
memberlist:
description: MemberList configuration spec
properties:
enableIPv6:
description: "EnableIPv6 enables IPv6 support for the memberlist
based hash ring. \n Currently this also forces the instanceAddrType
to podIP to avoid local address lookup for the memberlist."
type: boolean
instanceAddrType:
description: InstanceAddrType defines the type of address
to use to advertise to the ring. Defaults to the first address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: docker.io/grafana/loki-operator:main-99acb9b
createdAt: "2023-09-16T14:40:41Z"
createdAt: "2023-10-02T09:34:48Z"
description: The Community Loki Operator provides Kubernetes native deployment
and management of Loki and related logging components.
operators.operatorframework.io/builder: operator-sdk-unknown
Expand Down Expand Up @@ -265,6 +265,13 @@ spec:
- description: MemberList configuration spec
displayName: Memberlist Config
path: hashRing.memberlist
- description: "EnableIPv6 enables IPv6 support for the memberlist based hash
ring. \n Currently this also forces the instanceAddrType to podIP to avoid
local address lookup for the memberlist."
displayName: Enable IPv6
path: hashRing.memberlist.enableIPv6
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: InstanceAddrType defines the type of address to use to advertise
to the ring. Defaults to the first address from any private network interfaces
of the current pod. Alternatively the public pod IP can be used in case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ spec:
memberlist:
description: MemberList configuration spec
properties:
enableIPv6:
description: "EnableIPv6 enables IPv6 support for the memberlist
based hash ring. \n Currently this also forces the instanceAddrType
to podIP to avoid local address lookup for the memberlist."
type: boolean
instanceAddrType:
description: InstanceAddrType defines the type of address
to use to advertise to the ring. Defaults to the first address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
categories: OpenShift Optional, Logging & Tracing
certified: "false"
containerImage: quay.io/openshift-logging/loki-operator:v0.1.0
createdAt: "2023-09-16T14:40:45Z"
createdAt: "2023-10-02T09:34:52Z"
description: |
The Loki Operator for OCP provides a means for configuring and managing a Loki stack for cluster logging.
## Prerequisites and Requirements
Expand Down Expand Up @@ -278,6 +278,13 @@ spec:
- description: MemberList configuration spec
displayName: Memberlist Config
path: hashRing.memberlist
- description: "EnableIPv6 enables IPv6 support for the memberlist based hash
ring. \n Currently this also forces the instanceAddrType to podIP to avoid
local address lookup for the memberlist."
displayName: Enable IPv6
path: hashRing.memberlist.enableIPv6
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: InstanceAddrType defines the type of address to use to advertise
to the ring. Defaults to the first address from any private network interfaces
of the current pod. Alternatively the public pod IP can be used in case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ spec:
memberlist:
description: MemberList configuration spec
properties:
enableIPv6:
description: "EnableIPv6 enables IPv6 support for the memberlist
based hash ring. \n Currently this also forces the instanceAddrType
to podIP to avoid local address lookup for the memberlist."
type: boolean
instanceAddrType:
description: InstanceAddrType defines the type of address
to use to advertise to the ring. Defaults to the first address
Expand Down
5 changes: 5 additions & 0 deletions operator/config/crd/bases/loki.grafana.com_lokistacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ spec:
memberlist:
description: MemberList configuration spec
properties:
enableIPv6:
description: "EnableIPv6 enables IPv6 support for the memberlist
based hash ring. \n Currently this also forces the instanceAddrType
to podIP to avoid local address lookup for the memberlist."
type: boolean
instanceAddrType:
description: InstanceAddrType defines the type of address
to use to advertise to the ring. Defaults to the first address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ spec:
- description: MemberList configuration spec
displayName: Memberlist Config
path: hashRing.memberlist
- description: "EnableIPv6 enables IPv6 support for the memberlist based hash
ring. \n Currently this also forces the instanceAddrType to podIP to avoid
local address lookup for the memberlist."
displayName: Enable IPv6
path: hashRing.memberlist.enableIPv6
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: InstanceAddrType defines the type of address to use to advertise
to the ring. Defaults to the first address from any private network interfaces
of the current pod. Alternatively the public pod IP can be used in case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ spec:
- description: MemberList configuration spec
displayName: Memberlist Config
path: hashRing.memberlist
- description: "EnableIPv6 enables IPv6 support for the memberlist based hash
ring. \n Currently this also forces the instanceAddrType to podIP to avoid
local address lookup for the memberlist."
displayName: Enable IPv6
path: hashRing.memberlist.enableIPv6
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: InstanceAddrType defines the type of address to use to advertise
to the ring. Defaults to the first address from any private network interfaces
of the current pod. Alternatively the public pod IP can be used in case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ spec:
- description: MemberList configuration spec
displayName: Memberlist Config
path: hashRing.memberlist
- description: "EnableIPv6 enables IPv6 support for the memberlist based hash
ring. \n Currently this also forces the instanceAddrType to podIP to avoid
local address lookup for the memberlist."
displayName: Enable IPv6
path: hashRing.memberlist.enableIPv6
x-descriptors:
- urn:alm:descriptor:com.tectonic.ui:booleanSwitch
- description: InstanceAddrType defines the type of address to use to advertise
to the ring. Defaults to the first address from any private network interfaces
of the current pod. Alternatively the public pod IP can be used in case
Expand Down
14 changes: 14 additions & 0 deletions operator/docs/operator/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,20 @@ Alternatively the public pod IP can be used in case private networks (RFC 1918 a
are not available.</p>
</td>
</tr>
<tr>
<td>
<code>enableIPv6</code><br/>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>EnableIPv6 enables IPv6 support for the memberlist based hash ring.</p>
<p>Currently this also forces the instanceAddrType to podIP to avoid local address lookup
for the memberlist.</p>
</td>
</tr>
</tbody>
</table>

Expand Down
16 changes: 14 additions & 2 deletions operator/internal/manifests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,31 @@ func alertManagerConfig(spec *lokiv1.AlertManagerSpec) *config.AlertManagerConfi
}

func gossipRingConfig(stackName, stackNs string, spec *lokiv1.HashRingSpec) config.GossipRing {
var instanceAddr string
var (
instanceAddr string
enableIPv6 bool
)
if spec != nil && spec.Type == lokiv1.HashRingMemberList && spec.MemberList != nil {
switch spec.MemberList.InstanceAddrType {
case lokiv1.InstanceAddrPodIP:
instanceAddr = fmt.Sprintf("${%s}", gossipInstanceAddrEnvVarName)
instanceAddr = gossipInstanceAddrEnvVarTemplate
case lokiv1.InstanceAddrDefault:
// Do nothing use loki defaults
default:
// Do nothing use loki defaults
}

// Always default to use the pod IP address when IPv6 enabled to ensure:
// - On Single Stack IPv6: Skip interface checking
// - On Dual Stack IPv4/6: Eliminate duplicate memberlist node registration
if spec.MemberList.EnableIPv6 {
enableIPv6 = true
instanceAddr = gossipInstanceAddrEnvVarTemplate
}
}

return config.GossipRing{
EnableIPv6: enableIPv6,
InstanceAddr: instanceAddr,
InstancePort: grpcPort,
BindPort: gossipPort,
Expand Down
37 changes: 37 additions & 0 deletions operator/internal/manifests/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,43 @@ func TestConfigOptions_GossipRingConfig(t *testing.T) {
MembersDiscoveryAddr: "my-stack-gossip-ring.my-ns.svc.cluster.local",
},
},
{
desc: "IPv6 enabled with default instance address type",
spec: lokiv1.LokiStackSpec{
HashRing: &lokiv1.HashRingSpec{
Type: lokiv1.HashRingMemberList,
MemberList: &lokiv1.MemberListSpec{
EnableIPv6: true,
},
},
},
wantOptions: config.GossipRing{
EnableIPv6: true,
InstanceAddr: "${HASH_RING_INSTANCE_ADDR}",
InstancePort: 9095,
BindPort: 7946,
MembersDiscoveryAddr: "my-stack-gossip-ring.my-ns.svc.cluster.local",
},
},
{
desc: "IPv6 enabled with podIP instance address type",
spec: lokiv1.LokiStackSpec{
HashRing: &lokiv1.HashRingSpec{
Type: lokiv1.HashRingMemberList,
MemberList: &lokiv1.MemberListSpec{
EnableIPv6: true,
InstanceAddrType: lokiv1.InstanceAddrPodIP,
},
},
},
wantOptions: config.GossipRing{
EnableIPv6: true,
InstanceAddr: "${HASH_RING_INSTANCE_ADDR}",
InstancePort: 9095,
BindPort: 7946,
MembersDiscoveryAddr: "my-stack-gossip-ring.my-ns.svc.cluster.local",
},
},
}
for _, tc := range tt {
tc := tc
Expand Down
Loading

0 comments on commit 7c859fe

Please sign in to comment.